Enhancing Self-Attention with Knowledge-Assisted Attention Maps

Jiangang Bai, Yujing Wang, Hong Sun, Ruonan Wu, Tianmeng Yang, Pengfei Tang, Defu Cao, Mingliang Zhang, Yunhai Tong, Yaming Yang, Jing Bai, Ruofei Zhang, Hao Sun, Wei Shen

Introduction

Pre-trained language models (PLMs) like BERT have revolutionized Natural Language Processing by learning implicit semantic relationships from massive text corpora. However, these models often struggle with "rare word blindness"—a failure to comprehend infrequent or technical terms—and inefficient knowledge infusion, which typically requires expensive re-training or bulky adapter modules.

To address these challenges, we present KAM-BERT (Knowledge-assisted Attention Maps for BERT), a framework that explicitly guides a model's attention mechanism using external knowledge. By treating attention maps as an interface for knowledge injection, KAM-BERT offers a "plug-and-play" solution that enhances reasoning without the need for training from scratch.

Methodology

The core innovation of KAM-BERT is the introduction of Semantic Attention Maps. These maps act as auxiliary channels that highlight specific linguistic and factual relationships within an input sentence, effectively telling the model which token relationships deserve more focus.

Architecture of KAM-BERT illustrating the integration of semantic attention maps into the Transformer block.

Semantic Attention Maps

KAM-BERT utilizes three distinct types of knowledge-driven maps:

  1. Entity Map: This map explicitly links tokens belonging to the same named entity (e.g., "Fred" and "Meyer"), ensuring the model treats them as a single semantic unit.
  2. Phrase Segmentation Map: By highlighting words within the same syntactic phrase, this map preserves local structural information that might be lost in standard self-attention.
  3. Term Correlation Map: Leveraging Pointwise Mutual Information (PMI) from a large web corpus, this map connects semantically related words (e.g., "glipizide" and "pharmacy") even if they are distant in the sentence or rare in the pre-training data.

Multi-Channel Fusion

These semantic maps are concatenated with the "vanilla" self-attention map. A 2D-convolutional layer then fuses these channels, capturing spatial patterns in the attention matrix to produce a single, knowledge-enriched attention map. This approach allows the model to "nudge" its attention scores based on explicit facts while maintaining the strengths of the original pre-trained weights.

Experimental Results

KAM-BERT was evaluated across several benchmarks, demonstrating significant performance gains over standard PLMs with minimal additional parameters.

  • GLUE Benchmark: KAM-BERT-Base improved the average GLUE score from 77.5 to 78.7, with a notable 3.6-point jump in the CoLA (linguistic acceptability) task.
  • Question Answering: On the CosmosQA dataset, KAM-BERT-Large achieved a 10.6% accuracy improvement over BERT-Large, indicating a superior grasp of commonsense reasoning.
  • Efficiency: The framework achieves these results with very few extra parameters compared to "Adapter" based methods, making it computationally efficient during inference.

Industry Applications

The practical utility of KAM-BERT is most evident in specialized domains where rare terms are common. In a large-scale Query-Ad Relevance task for a commercial search engine, the model significantly improved AUC (Area Under Curve).

Application of KAM-BERT to the Query-Ad Relevance task in a commercial search engine.

In this context, the Term Correlation map is particularly valuable. It prevents the model from "getting lost" when encountering rare product or drug names by statistically linking them to more common, related terms, thereby improving the relevance of search results.

Conclusion and Future Work

KAM-BERT demonstrates that the attention map is an ideal location for knowledge injection. While the current implementation relies on external pre-processing tools for NER and syntax parsing, future iterations could incorporate more complex structures such as full Knowledge Graphs or hierarchical taxonomies. By providing a flexible, plug-and-play mechanism for knowledge infusion, KAM-BERT paves the way for more robust and domain-aware language models.

Summary updated

BibTeX
@inproceedings{bai2022enhancing,
  author = {Jiangang Bai and Yujing Wang and Hong Sun and Ruonan Wu and Tianmeng Yang and Pengfei Tang and Defu Cao and Mingliang Zhang and Yunhai Tong and Yaming Yang and Jing Bai and Ruofei Zhang and Hao Sun and Wei Shen},
  title = {{Enhancing Self-Attention with Knowledge-Assisted Attention Maps}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2022},
  doi = {10.18653/v1/2022.naacl-main.8},
}
Figure