Abstract
Traditional text classification models often rely on a static label set, failing to adapt to "in-the-wild" scenarios where categories emerge or disappear dynamically. We present ModularPrompt, a framework that decomposes task knowledge into discrete, label-specific modules. By learning independent "label prompts" and employing a subset-invariant training strategy, ModularPrompt enables models to handle dynamic label sets without retraining. Our experiments across news classification, named entity recognition, and relation extraction demonstrate that ModularPrompt significantly outperforms standard continual learning and prompt-tuning baselines, even surpassing multitask oracles in some settings while using only 0.13M tunable parameters.
Introduction
Most machine learning models operate under the "i.i.d. assumption," where training and testing data are drawn from the same static distribution. However, real-world NLP tasks are frequently non-stationary. For instance, a news classifier might need to incorporate a "COVID-19" category overnight or retire an obsolete category. This phenomenon, termed Text Classification In-The-Wild, poses significant challenges for existing methods.
Full fine-tuning is computationally prohibitive and susceptible to "catastrophic forgetting"—the loss of knowledge about old labels when learning new ones. Standard prompt tuning, while more efficient, typically learns a single sequence of continuous "soft tokens" for an entire task. This entanglement of knowledge makes it difficult to add or remove specific classes without retraining the entire prompt. To address this, we propose a modular approach where knowledge for each category is stored independently.
Methodology
ModularPrompt shifts the paradigm from task-level prompts to label-level prompts. The core architecture consists of three main components:
Label Modular Architecture
Instead of a single global prompt, the input to the Pre-trained Language Model (PLM) includes a sequence of label-specific prompts ($l_i, \dots, l_k$) alongside the text input $X$. Each label prompt $l_i$ is a combination of the label's natural language name (e.g., "Politics") and a short sequence of learnable "soft tokens" ($p_1^i, \dots, p_m^i$).
Subset Invariant Loss
To ensure the model does not rely on a fixed label set, we introduce a subset-invariant training strategy. During training, we randomly sample subsets of labels for each batch. This forces the model to ground its predictions specifically in the label prompts present in the current input, rather than relying on the global context of the entire label set.
Label Prompt Transfer
When transitioning to new training stages with novel labels, ModularPrompt initializes new label prompts by taking a weighted average of semantically similar existing prompts. For example, knowledge learned for "Bistro" can help initialize the prompt for "Restaurant," facilitating faster convergence and knowledge reuse.
Experiments and Results
We evaluated ModularPrompt on three distinct tasks: Huffpost News (41 labels), FewNERD (64 labels), and FewRel (80 labels). These were split into sequential training stages to simulate "in-the-wild" conditions. We tested performance in three settings: Stage-specific (current labels), Stage-agnostic (all seen labels), and Stage-fused (a mix of labels from different stages).
As shown in the table above, ModularPrompt consistently outperforms baselines. In the challenging "Stage-Fused" scenario, it surpassed other methods by an average margin of 37.5%. Notably, on News Classification and NER, it performed 4-14% better than a "Multitask" oracle trained on all data simultaneously. This performance is achieved with extreme efficiency, requiring only 0.13M tunable parameters compared to the 770M parameters of a full T5-large model.
Discussion
Our analysis reveals several key insights:
- Knowledge Grounding: The model's knowledge is truly modular. Removing the ground-truth label prompt during testing causes accuracy to drop to near zero, while removing unrelated prompts has minimal impact.
- Compositionality: Soft prompts act as linguistic building blocks. They can be concatenated in any order at inference time without performance loss, demonstrating "low order sensitivity."
- Semantic Priors: Incorporating actual label names allows the model to leverage the pre-trained knowledge of the PLM to bridge gaps between training stages.
Conclusion and Future Work
ModularPrompt provides a robust and efficient solution for dynamic text classification. While highly effective, the method currently faces scalability limits due to the transformer's context window, as the prompt length grows linearly with the number of labels. Future work will explore hierarchical modular prompts and treating label prompts as external memory units to support larger label spaces. Additionally, extending this modularity to unstructured generation tasks remains an open research challenge.
Summary updated