Text Matching as Image Recognition

Liang Pang, Yanyan Lan, Jiafeng Guo, Jun Xu, Shengxian Wan, Xueqi Cheng

TL;DR

MatchPyramid re-imagines text matching as an image recognition problem. By constructing a 2D "matching matrix" of word similarities and processing it with a Convolutional Neural Network (CNN), the model automatically learns to identify hierarchical patterns—from simple word overlaps to complex phrase-level semantic relationships.

What Problem Does This Paper Address?

Matching two pieces of text is a cornerstone of NLP, essential for tasks like paraphrase identification, question answering, and document retrieval. The core challenge lies in capturing "interaction structures" across different granularities.

Consider two sentences: "Noodles and dumplings are famous" and "Dumplings and noodles are popular." A robust matching algorithm needs to recognize:

  1. Word-level signals: Direct matches like "noodles" to "noodles."
  2. Phrase-level signals: Recognizing that "noodles and dumplings" is a reordered version of "dumplings and noodles."
  3. Sentence-level signals: Understanding that the overall meaning is preserved despite lexical variations like "famous" vs. "popular."

Previous models often compressed each text into a single vector before comparison, a process that frequently discards these granular, hierarchical interactions.

The analogy between hierarchical image recognition and text matching signals.

Methods: The MatchPyramid Architecture

The authors propose MatchPyramid, which treats the interaction between two texts as a 2D image, allowing the model to leverage the spatial pattern-recognition capabilities of CNNs.

1. The Matching Matrix (Layer-0)

Given two texts, $T_1$ and $T_2$, the model builds a matrix where each entry $(i, j)$ represents the similarity between the $i$-th word of $T_1$ and the $j$-th word of $T_2$. Three similarity functions were explored:

  • Indicator: A binary (0 or 1) match, creating a high-contrast "black-and-white" image of exact word overlaps.
  • Cosine Similarity: Uses word embeddings to capture semantic closeness, resulting in a "grayscale" image.
  • Dot Product: Similar to cosine but accounts for the magnitude (norm) of word vectors, which often correlates with word importance.

2. Hierarchical Convolution and Pooling

Just as a CNN in computer vision identifies edges, then motifs, and finally objects, MatchPyramid uses successive convolution layers to scan the matching matrix.

  • Convolution: A diagonal line in the matrix represents an n-gram match (sequences of words in the same order). More complex kernels can identify n-term matches (words appearing near each other but reordered).
  • Dynamic Pooling: Since sentences vary in length, the model employs a dynamic pooling strategy. This downsamples convolutional feature maps into a fixed size, ensuring compatibility with the final Multi-Layer Perceptron (MLP) that generates the matching score.
The MatchPyramid architecture, showing the transition from a matching matrix to convolutional layers and final matching score.

Datasets and Evaluation

The model was evaluated on two distinct tasks:

  • MSRP (Microsoft Research Paraphrase Corpus): A standard benchmark for paraphrase identification containing 5,801 sentence pairs.
  • Paper Citation Matching: A large-scale dataset (over 800,000 pairs) where the goal is to determine if a specific paper abstract cites another based on their content.

Key Insights

  • Text as Vision: Text matching patterns have distinct "spatial" signatures. An exact phrase match appears as a solid diagonal line, while a reordered phrase looks like a cluster of dots. CNNs are mathematically optimized to detect these shapes.
  • The Importance of Norms: In citation matching, the Dot Product version (MP-DOT) significantly outperformed the Cosine version (MP-COS). The authors found that domain-specific words (e.g., robotics) have larger vector norms than common stop words. The dot product preserves this "importance" signal, whereas cosine normalization discards it.
  • End-to-End Learning: MatchPyramid learns hierarchical features directly from raw word interactions, removing the need for manual feature engineering or external parsers.

Results and Limitations

On the MSRP dataset, MatchPyramid (MP-DOT) achieved an accuracy of 75.94% and an F1 score of 83.01, outperforming established deep learning baselines like ARC-II. In citation matching, it reached 88.73% accuracy, significantly beating the traditional TF-IDF baseline (82.63%).

Limitations: * External Knowledge: While highly effective, MatchPyramid was slightly outperformed on MSRP by models using external syntactic parse tree information. * Complexity: Constructing a full $N \times M$ matrix for very long documents (e.g., books) may be computationally expensive. * Scaling: Future work is needed to determine if the "image recognition" metaphor holds for much larger "images" (longer texts) beyond the 32-word abstracts tested.

Summary updated

BibTeX
@inproceedings{pang2016text,
  author = {Liang Pang and Yanyan Lan and Jiafeng Guo and Jun Xu and Shengxian Wan and Xueqi Cheng},
  title = {{Text Matching as Image Recognition}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2016},
  doi = {10.1609/aaai.v30i1.10341},
}
Figure