[Paper Review] Mask-guided BERT for Few Shot Text Classification
This paper proposes Mask-BERT, a novel few-shot text classification framework that enhances BERT's performance by applying learnable masks to filter irrelevant tokens and guiding attention toward discriminative features. By integrating contrastive learning with anchor samples from the base domain, Mask-BERT achieves state-of-the-art results on both open-domain and medical NLP benchmarks, outperforming prompt-tuning and meta-learning methods with improved robustness and stability across varying mask ratios.
Transformer-based language models have achieved significant success in various domains. However, the data-intensive nature of the transformer architecture requires much labeled data, which is challenging in low-resource scenarios (i.e., few-shot learning (FSL)). The main challenge of FSL is the difficulty of training robust models on small amounts of samples, which frequently leads to overfitting. Here we present Mask-BERT, a simple and modular framework to help BERT-based architectures tackle FSL. The proposed approach fundamentally differs from existing FSL strategies such as prompt tuning and meta-learning. The core idea is to selectively apply masks on text inputs and filter out irrelevant information, which guides the model to focus on discriminative tokens that influence prediction results. In addition, to make the text representations from different categories more separable and the text representations from the same category more compact, we introduce a contrastive learning loss function. Experimental results on public-domain benchmark datasets demonstrate the effectiveness of Mask-BERT.
Motivation & Objective
- To address the challenge of overfitting and poor generalization in few-shot text classification due to limited labeled data.
- To develop a simple, modular alternative to complex prompt-tuning and meta-learning methods for few-shot NLP.
- To improve model robustness and generalization by focusing attention on discriminative tokens through learnable masking.
- To enhance feature separability and compactness across classes using contrastive learning with stable anchor samples.
Proposed method
- A learnable masking mechanism is applied to input text to filter out low-contribution tokens and guide BERT’s attention toward more discriminative features.
- Anchor samples from the base dataset are used to stabilize representation learning and guide the model during novel class adaptation.
- A contrastive learning loss is introduced to minimize intra-class variance and maximize inter-class margin in the embedding space.
- The framework is trained via fine-tuning on a base dataset and then adapted to novel classes with only a few labeled samples.
- The mask ratio is varied from 0.05 to 0.85, and the model shows stable performance across this range, indicating robustness.
- Intermediate representations are visualized using UMAP to demonstrate improved class separation and reduced clustering compared to standard BERT.

Experimental results
Research questions
- RQ1Can a learnable masking strategy improve few-shot text classification performance without relying on prompt engineering?
- RQ2How does the integration of anchor samples and contrastive learning affect model generalization in low-resource settings?
- RQ3Does the proposed masking mechanism lead to more stable and robust performance across different mask ratios?
- RQ4Can Mask-BERT outperform existing prompt-tuning and meta-learning baselines in few-shot text classification tasks?
Key findings
- Mask-BERT achieves the best performance on medical-domain datasets among all compared methods, outperforming BERT, Re-init-BERT, CNN-BERT, and FPT-BERT.
- On the AG News and NICTA-PIBOSO datasets, the ablation study shows that adding contrastive loss improves accuracy from 0.753 to 0.821 (±0.040) in the 5-shot setting.
- The inclusion of both anchor samples and masking leads to a 0.012 improvement in accuracy over using only contrastive loss (0.809 to 0.821).
- The model maintains high stability across mask ratios, with an average standard deviation of only 0.006 in accuracy across all datasets.
- Visualization results show that Mask-BERT produces more evenly distributed and compact class clusters than standard BERT, especially in the novel class space.
- The method effectively reduces the formation of large, overlapping clusters in the embedding space, which commonly hinders classification in few-shot scenarios.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.