Specialized Language Models with Cheap Inference from Limited Domain Data

David Grangier, Angelos Katharopoulos, Pierre Ablin, Awni Hannun

Abstract

Large language models are versatile tools but are not suitable for small inference budgets. Small models have more efficient inference, but their lower capacity means that their performance can be good only if one limits their scope to a specialized domain. This paper explores how to get good specialized small language models using a large, generic, pretraining set and a limited amount of specialized data. We consider two scenarios, depending on whether (i) one can afford pretraining a model for each specialization task, or (ii) one wants to cheaply adapt a single pretrained model for each task. In the first scenario, we propose an effective solution based on importance sampling: we resample the pretraining set to imitate the specialization data and train a small model on it. In the second scenario, we propose a novel architecture, projected networks (PN). PN is a large network whose parameters can be linearly projected into a small network for specialization. For both scenarios, we demonstrate the empirical effectiveness of our solutions across various domains, training set sizes, and training budgets.

Introduction

Large Language Models (LLMs) are powerful but carry a significant "inference tax." Their massive parameter counts make them slow and expensive to deploy in production environments. While Small Language Models (SLMs) offer a faster, cheaper alternative, they typically lack the capacity to handle general tasks effectively.

The central challenge addressed in this research is how to develop SLMs that excel in specific domains (e.g., legal, medical, or scientific) when only a limited amount of specialized data is available. Standard fine-tuning often leads to overfitting on small datasets. This paper argues that the key to high-performing SLMs lies in the pretraining phase—specifically, planning for specialization from the start.

Decision tree for selecting a model strategy based on inference and specialization budgets.

Methodology

The researchers propose two primary strategies based on the available specialization budget:

1. Importance Sampling (SLM-is)

For scenarios where a dedicated pretraining run for a single domain is feasible, the authors suggest Importance Sampling. Instead of training on a random slice of a generic dataset like C4, the generic data is clustered and resampled to mimic the distribution of the target domain. This "pre-specializes" the model, allowing it to develop relevant features before it even encounters the actual domain-specific data.

2. Projected Networks (SLM-pn)

In cases where multiple specialized models are needed (e.g., separate models for legal and medical tasks), training individual models is cost-prohibitive. The authors introduce Projected Networks, a novel architecture where a large "super-network" is trained such that its parameters can be linearly projected into smaller, specialized "expert" networks. This allows the heavy pretraining cost to be shared across many potential tasks, enabling the rapid "spawning" of specialized models on demand.

These methods were compared against standard baselines, including vanilla fine-tuning and Knowledge Distillation (SLM-d), where a large teacher model guides the training of a smaller student.

Experimental Setup

The study utilized the C4 dataset for generic pretraining and nine diverse subsets from The Pile for specialized domains, including Arxiv (Science), FreeLaw (Legal), PubMed (Medical), and StackExchange (Technical). The researchers tested specialization across various data scales—1M, 8M, and 64M tokens—to evaluate performance under extreme data scarcity.

Key Results and Insights

  • Performance Parity: With as little as 1 million tokens (roughly 10 books), an SLM trained using importance sampling can compete with an LLM six times its size on specialized tasks. As shown in the results, the SLM-is approach significantly outperforms standard SLM baselines and rivals the LLM in specific perplexity.
  • Inference Efficiency: The SLMs (126M parameters) achieved inference speeds approximately 4x faster than the LLM baseline (771M parameters).
  • The "Plan Early" Advantage: The most effective models were those where pretraining data was curated to resemble the target domain from day one. Fine-tuning remains essential, but it cannot compensate for a generic pretraining phase in low-capacity models.
  • Distillation Costs: While effective, the authors found that the high cost of training the large "teacher" model for distillation often makes it less cost-effective than importance sampling or projected networks.
Comparison of specialized perplexity across different model types as a function of pretraining cost.

Limitations and Future Work

The study primarily focused on 126M parameter models; future research is needed to determine if these advantages scale to medium-sized models. Additionally, the reliance on Sentence-BERT for clustering suggests that different embedding techniques could further influence results. Finally, while this work focused on language, the "plan early" philosophy could potentially be applied to other domains like computer vision where inference constraints are similarly critical.

Summary updated

BibTeX
@misc{grangier2024specialized,
  author = {David Grangier and Angelos Katharopoulos and Pierre Ablin and Awni Hannun},
  title = {{Specialized Language Models with Cheap Inference from Limited Domain Data}},
  year = {2024},
  eprint = {2402.01093},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.01093},
}
Figure