Multi-Level Head-Wise Match and Aggregation in Transformer for Textual Sequence Matching

Shuohang Wang, Yunshi Lan, Yi Tay, Jing Jiang

Introduction

Textual sequence matching is a fundamental task in Natural Language Processing (NLP), essential for applications such as duplicate detection, question answering, and natural language inference. This paper introduces a novel architecture that leverages the power of pre-trained Transformers while maintaining the efficiency required for large-scale retrieval. By matching individual attention heads across multiple layers, the proposed Multi-level Head-wise Match (MHM) model bridges the gap between high-accuracy interaction-based models and high-speed representation-based models.

The Speed-Accuracy Trade-off

Current approaches to sequence matching generally fall into two categories:

  1. Cross-Sentence Attention (Interaction-based): Models like BERT process sentence pairs together, allowing for fine-grained token-level interactions. While highly accurate, this is computationally expensive, making it impractical for searching large databases in real-time. To find a match in a pool of 10,000, BERT would require nearly 50 million runs.
  2. Sentence Vectors (Representation-based): These models pre-compute a fixed-length vector for each sentence. Matching is performed using simple metrics like cosine similarity. Although extremely fast (reducing hours of computation to seconds), this approach often suffers from information loss, as complex semantic nuances are compressed into a single vector.

The MHM approach aims to mitigate this loss by preserving the internal structure of the Transformer's representations during the matching process.

Multi-level Head-wise Match (MHM)

The core innovation of this work lies in how it compares the representations generated by a Transformer. Instead of collapsing the multi-head attention output into a single vector, the authors propose two key strategies:

Head-wise Matching

In a standard Transformer, each layer contains multiple attention heads, each specializing in different linguistic features (e.g., syntax, specific keywords). Traditional models often average or concatenate these heads into a single representation, which can introduce noise. MHM performs a 1-to-1 match between the $i$-th head of the source sentence and the $i$-th head of the target sentence. This preserves the specific semantic alignments captured by each head.

Multi-level Aggregation

Rather than relying solely on the final layer of the Transformer, MHM extracts head-wise matches from every layer. This recognizes that lower layers capture syntactic information while higher layers capture more abstract semantics.

Multi-level aggregation architecture across Transformer layers.

Matching and Aggregation Functions

The authors explored various matching functions to compare heads. They found that an element-wise matching function—which concatenates the original vectors, their absolute difference, and their element-wise product—outperformed simpler methods like cosine similarity or bilinear forms.

Comparison of different matching functions: (e) cosine similarity, (f) bilinear match, and (g) element-wise match.

Finally, a max-pooling layer aggregates these individual head matches into a final score for classification. This allows the model to dynamically focus on the most informative heads while filtering out noise.

Experimental Results

The MHM model was evaluated on five benchmark datasets: SNLI, MNLI (matched and mismatched), QQP, and SQuAD-binary. It achieved new state-of-the-art results for sentence-vector-based models:

  • SNLI: 88.1% accuracy, a significant jump over the "Classic Match" baseline of 83.2%.
  • MNLI: 79.2% accuracy on the matched set, outperforming previous bests like BiLSTM+ELMo.
  • Efficiency: MHM maintains the scalability of representation-based models, enabling rapid retrieval from large pools of candidates while approaching the accuracy of full cross-attention models.

Discussion and Future Work

The results demonstrate that the internal structure of Transformers—specifically the individual attention heads—contains rich information that is often lost in standard pooling operations. By matching heads directly, MHM captures fine-grained semantic overlaps more effectively.

However, a performance gap of 3-4% still exists compared to full cross-attention models. Additionally, the model's performance on long-form text (like SQuAD) suggests that compressing long paragraphs into head-wise structures remains a challenge. Future research may focus on more sophisticated head selection mechanisms or applying MHM to even larger pre-trained architectures.

Summary updated

BibTeX
@inproceedings{wang2020multi,
  author = {Shuohang Wang and Yunshi Lan and Yi Tay and Jing Jiang and Jingjing Liu},
  title = {{Multi-Level Head-Wise Match and Aggregation in Transformer for Textual Sequence Matching}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2020},
  doi = {10.1609/aaai.v34i05.6458},
}
Figure