A Domain-Finetuned Semantic Matching Framework Based on Dynamic Masking and Contrastive Learning for Specialized Text Retrieval

Yiming Zhang, Yong Zhu, Zijie Zhu, Pu‐Kun Liu, Pengfei Xie, Cong WuElectronics 2025

TL;DR

This paper introduces a novel framework for domain-specific semantic matching that tackles limitations of existing models like BERT. By combining a "dynamic masking" strategy that focuses on critical words with "contrastive learning" using domain-specific data, the model significantly improves its ability to understand and retrieve relevant text within specialized domains, even with limited labeled data.

What Problem Does This Paper Address?

Understanding the semantic relationship between pieces of text is crucial for many Natural Language Processing (NLP) tasks, such as question answering, dialogue systems, and information retrieval. While powerful pre-trained models like BERT have advanced this field, they face challenges when applied to specialized domains. Specifically, their "random masking" strategy during pre-training doesn't prioritize the most important words for semantic meaning. Furthermore, BERT's sentence embeddings can suffer from "collapse," where distinct sentences end up with very similar vector representations, making it hard to differentiate them. This paper aims to address these issues by developing a framework that can effectively fine-tune semantic matching models for specific domains, improving their accuracy and robustness, especially when dealing with limited domain-specific labeled data.

Methods

The core of this paper's contribution lies in its novel domain-finetuned semantic matching framework, which integrates two key components:

  • Domain-Finetuned Pre-training by Dynamic Masking: Instead of the standard random masking used in models like BERT, this approach uses a self-supervised dynamic masking strategy. It intelligently identifies and masks the most semantically important tokens within a sentence by analyzing the model's own difficulty in predicting them (based on cross-entropy loss). This forces the model to focus on critical semantic cues, enhancing its understanding of domain-specific language.
  • Transfer Training by Contrastive Learning: To combat the "representation collapse" issue and improve sentence embeddings, the framework employs contrastive learning. Crucially, it uses naturally occurring, semantically equivalent sentence pairs from the target domain as positive examples. This preserves the authenticity of domain terminology, unlike methods that rely on synthetic augmentations (like back-translation) which can distort specialized vocabulary. Negative samples are other sentences within the same batch. This approach helps to pull similar sentences closer in the embedding space and push dissimilar ones further apart, creating more discriminative representations.

These two components are integrated into an end-to-end framework that also includes text vectorization and a Transformer encoder for knowledge transfer.

Datasets

The study utilizes the LES Cup dataset, a large-scale Chinese reading comprehension corpus tailored to military application scenarios. To evaluate domain-specific performance, they construct three domain-specific evaluation subsets: maritime, ground, and airspace. For model adaptation, they construct a structured training set of synthetic "codename: formal name" pairs for contrastive learning. The evaluation is performed on a consolidated dataset comprising all three subsets, using held-out passages.

Key Insights and Ideas

  • Dynamic Masking is Key for Domain Focus: The paper highlights that focusing on semantically critical words, identified dynamically based on the model's own learning process, is more effective than random masking for domain-specific semantic understanding.
  • Authentic Data for Contrastive Learning: Using naturally occurring, domain-specific sentence pairs for contrastive learning is crucial for preserving the integrity of specialized terminology and achieving better semantic alignment. Synthetic augmentations can introduce unwanted distortions.
  • Synergy for Robustness: The combination of dynamic masking and contrastive learning creates a powerful synergy. Dynamic masking enhances feature extraction, while contrastive learning regularizes the embedding space, leading to more cohesive and discriminative representations.
  • Low-Resource Domain Adaptation: The framework demonstrates strong performance even with limited domain-specific data, making it highly valuable for specialized applications where large labeled datasets are scarce.

Key Results

The proposed framework shows significant improvements over baseline models like SBERT and Text2vec:

  • Semantic Similarity: After private domain training, the model improves semantic similarity between entities by 16.9%.
  • General Semantic Matching: An 8.0% average improvement in semantic matching for diverse text is observed.
  • Retrieval Accuracy (A@1, A@3, A@5): Performance metrics are at least 26.1% higher than competing models.
  • New Entities: For newly added entities (unseen during training), the model achieves a 44.3% average improvement, consistently surpassing other models by at least 30%.
  • Vector Differences: Heatmaps show a substantial reduction in mean vector differences after training, indicating more cohesive and discriminative embedding spaces.
  • Confusion Matrices: The model demonstrates a clearer differentiation between intra-class and inter-class similarities compared to baselines.

Limitations and Future Work

  • Heuristic Significance Estimation: The dynamic masking strategy still relies on some heuristic estimations of significance, which might not perfectly capture all contextual semantic importance.
  • Uninformative Negative Samples: In data-scarce scenarios, the contrastive learning component might be vulnerable to uninformative negative samples.
  • Cross-Domain Transfer: The model's cross-domain generalization capability requires further verification, as its performance is dependent on the availability of representative domain-specific corpora.
  • Exposure Bias: A subtle "exposure bias" exists because the model is trained with masked inputs but infers on unmasked inputs. Future work could explore techniques like imitation learning or curriculum learning to mitigate this.
  • Future Directions: The authors suggest exploring more sophisticated dynamic masking algorithms, extending the model to a broader range of downstream tasks, investigating methods for constructing pre-training corpora, and developing techniques to automatically extract key semantic information from pre-trained models.

Summary updated

Abstract

Semantic matching is essential for understanding natural language, but traditional models like BERT face challenges with random masking strategies, limiting their ability to capture key information. Additionally, BERT’s sentence vectors may “collapse,” making it difficult to distinguish between different sentences. This paper introduces a domain-finetuned semantic matching framework that uses dynamic masking and contrastive learning techniques to address these issues. The dynamic masking strategy enhances the model’s ability to retain critical information, while contrastive learning improves sentence vector representations using a small amount of unlabeled text. This approach helps the model better align with the needs of various downstream tasks. Experimental results show that after private domain training, the model improves semantic similarity between entities by 16.9%, outperforming existing models. It also demonstrates an 8.0% average improvement in semantic matching for diverse text. Performance metrics such as A@1, A@3, and A@5 are at least 26.1% higher than those of competing models. For newly added entities, the model achieves a 44.3% average improvement, consistently surpassing other models by at least 30%. These results collectively validate the effectiveness and superiority of the proposed framework in domain-specific semantic matching tasks.
BibTeX
@inproceedings{zhang2025domain,
  author = {Yiming Zhang and Yong Zhu and Zijie Zhu and Pu‐Kun Liu and Pengfei Xie and Cong Wu},
  title = {{A Domain-Finetuned Semantic Matching Framework Based on Dynamic Masking and Contrastive Learning for Specialized Text Retrieval}},
  booktitle = {Electronics},
  year = {2025},
  doi = {10.3390/electronics14244882},
}
Figure