Regex-augmented Domain Transfer Topic Classification based on a Pre-trained Language Model: An application in Financial Domain

Vanessa Liao, Syed Shariyar Murtaza, Yifan Nie, Jimmy LinarXiv 2023 · DOI · arXiv

Abstract

Topic classification in specialized domains such as insurance and finance often faces the challenge of data scarcity and highly technical terminology. While Large Language Models (LLMs) like BERT provide strong general language understanding, they frequently underperform in these "niche" settings without extensive fine-tuning data. This paper introduces a hybrid architecture that augments a pre-trained BERT model with domain-specific regular expression (regex) features. By employing a self-attention mechanism to fuse these features, the proposed model achieves a 20.75% improvement in F1-score over standard BERT fine-tuning on a real-world industrial dataset.

Introduction

In corporate environments, accurately categorizing customer feedback is crucial for operational efficiency. However, industries like insurance rely on specialized jargon that generic LLMs, pre-trained on corpora like Wikipedia, may not fully grasp. Traditional rule-based methods (e.g., regex) are precise but brittle, failing to capture semantic variations. Conversely, fine-tuning deep learning models requires large labeled datasets, which are often unavailable in specialized domains. This research addresses the "domain transfer" gap by combining the semantic power of BERT with the precision of expert-defined regex rules.

Methodology

The core of the proposed solution is a "Regex-augmented" architecture that treats domain knowledge as a primary feature alongside raw text. The pipeline consists of the following stages:

  1. Dual Input Channels: The system processes survey text through two parallel paths. One path utilizes a standard pre-trained BERT encoder to extract contextual representations. The second path applies 27 hand-crafted regex rules, developed by domain experts, to identify specific keywords or patterns.
  2. Feature Embedding and Fusion: Discrete hits from regex rules are converted into embeddings. Rather than simple concatenation, the model uses a Transformer Encoder with four attention heads to dynamically weight the relevance of regex features relative to the BERT context.
  3. Classification: The fused representation is passed through a feed-forward neural network with a sigmoid output layer for multi-label classification.
Proposed Regex-augmented BERT architecture.

Additionally, the model includes an "Emerging Topic" safety net. If the confidence score for all predefined topics falls below a threshold, the input is flagged for human review, allowing for the discovery of new customer concerns.

Experimental Setup

The study utilized a private industrial dataset from Manulife, consisting of 541 manually labeled customer service feedback samples. The dataset covers 27 distinct topics (e.g., "Claim Result," "Agent Service Quality"). The data is characterized by an average text length of 47 words and a highly imbalanced distribution, reflecting real-world feedback patterns.

Key Results

The researchers evaluated five model configurations to determine the impact of regex augmentation and fusion strategies.

Performance comparison of different model configurations.

As shown in the results table, Model 5 (BERT + Regex + Attention) significantly outperformed the baselines:

  • F1-Score: Model 5 achieved a weighted F1-score of 0.64, a substantial increase over the 0.53 achieved by BERT-only (Model 2).
  • Relative Improvement: This represents a 20.75% improvement over standard fine-tuning.
  • Production Impact: Deployment of this model led to a 40% increase in user satisfaction ratings for topic coverage and a 58.33% increase in precision ratings compared to the legacy system.

Discussion

The results highlight that regex acts as a "shortcut" for learning in low-data regimes. By providing explicit "hints" about technical terms, the model compensates for the lack of thousands of training examples. Furthermore, the superiority of attention-based fusion over linear layers suggests that the model benefits from understanding the contextual relationship between rule-based hits and the broader text.

Conclusion

This paper demonstrates that "old-school" rule-based logic can significantly enhance modern transformer performance in industrial settings. Future work will focus on validating this architecture across other specialized domains such as healthcare and exploring more sophisticated feature engineering beyond regex.

Summary updated

Abstract

A common way to use large pre-trained language models for downstream tasks is to fine tune them using additional layers. This may not work well if downstream domain is a specialized domain whereas the large language model has been pre-trained on a generic corpus. In this paper, we discuss the use of regular expression patterns employed as features for domain knowledge during the process of fine tuning, in addition to domain specific text. Our experiments on real scenario production data show that this method of fine tuning improves the downstream text classification tasks as compared to fine tuning only on domain specific text. We also show that the use of attention network for fine tuning improves results compared to simple linear layers.
BibTeX
@misc{liao2023regex,
  author = {Vanessa Liao and Syed Shariyar Murtaza and Yifan Nie and Jimmy Lin},
  title = {{Regex-augmented Domain Transfer Topic Classification based on a Pre-trained Language Model: An application in Financial Domain}},
  year = {2023},
  eprint = {2305.18324},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.18324},
}
Figure