Shortest-Path Graph Kernels for Document Similarity

Giannis Nikolentzos, Polykarpos Meladianos, François Rousseau, Yannis Stavrakas, Michalis Vazirgiannis

Introduction

Traditional document similarity measures predominantly rely on the Vector Space Model (VSM), which operates under the "bag-of-words" assumption. By treating words as independent entities, VSM ignores the structural and contextual relationships that define meaning. While $n$-grams attempt to capture local context, they are inherently rigid and fail to recognize similarity when word order is slightly permuted or when related terms are separated by a few positions.

This paper introduces a novel approach that represents documents as graphs-of-words. By applying a modified shortest-path graph kernel (SPGK), the authors capture both structural and statistical relationships between words, providing a more flexible and robust measure of document similarity than traditional vector-space models or even some deep learning architectures.

Methodology: The Graph-of-Words Model

The proposed method involves a two-step process to transform raw text into a comparable structural format.

1. Graph Construction

Each document is converted into an unweighted, undirected graph. Vertices represent unique terms (following standard stemming and stop-word removal). Edges are established between terms that co-occur within a fixed-size sliding window. This representation allows the model to capture dependencies that linear sequences might miss.

Figure 1: Example of a graph-of-words representation for the phrase "to be or not to be that is the question."

2. Shortest-Path Graph Kernel (SPGK)

To compare two document graphs, the authors utilize a modified shortest-path kernel. The original graph $G$ is transformed into a new graph $C$, where an edge exists between two nodes if their shortest path distance in $G$ is less than or equal to a parameter $d$. Edges in $C$ are weighted by $1/p$ (where $p$ is the shortest path distance), effectively rewarding proximity. The final similarity is calculated by summing the similarities of all pairs of nodes and edges between the two graphs, normalized by the Frobenius norm of their adjacency matrices.

Experimental Results

The researchers evaluated the SPGK approach against standard baselines (Dot product, Cosine, Tanimoto) and deep learning models (DCNN, CNN) across five diverse text categorization datasets: WebKB, News, Subjectivity, Amazon, and Polarity.

Figure 3: Performance comparison (Accuracy and F1-score) of SPGK against various baselines and deep learning models across five datasets.

Key Findings

  • Superior Accuracy: As shown in the results table, SPGK (particularly with $d=2$) achieved the highest accuracy on 4 out of 5 datasets. It consistently outperformed traditional VSM measures like Cosine and Tanimoto similarity.
  • Comparison with Deep Learning: Surprisingly, the graph-based approach outperformed complex neural networks such as CNNs and DCNNs on several datasets. This suggests that for datasets of moderate size, the explicit structural information captured by graph kernels can be more effective than the representations learned by deep models.
  • Structural Flexibility: The model proved robust to word inversions and subset matching, successfully capturing long-range dependencies through the $d$ parameter.
  • Efficiency: For $d=1$, the algorithm runs in $O(n+m)$ time, making it computationally competitive with traditional VSM approaches while providing superior performance.

Conclusion

The shortest-path graph kernel offers a powerful alternative to the bag-of-words model by explicitly modeling the structural relationships within text. Its domain independence and computational efficiency make it a viable candidate for various NLP tasks, from text categorization to story link detection. Future work may involve integrating word embeddings into the node similarity function to combine structural graph information with semantic word meanings.

Summary updated

BibTeX
@inproceedings{nikolentzos2017shortest,
  author = {Giannis Nikolentzos and Polykarpos Meladianos and François Rousseau and Yannis Stavrakas and Michalis Vazirgiannis},
  title = {{Shortest-Path Graph Kernels for Document Similarity}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2017},
  doi = {10.18653/v1/d17-1202},
}
Figure