Convolutional Neural Networks for Text Hashing

Jiaming Xu, Peng Wang, Guanhua Tian, Bo Xu, Jun Zhao, Fangyuan Wang, Hongwei HaoIJCAI 2015

Abstract

Hashing, as a popular approximate nearest neighbor search, has been widely used for large-scale similarity search. Recently, a spectrum of machine learning methods are utilized to learn similarity-preserving binary codes. However, most of them directly encode the explicit features, keywords, which fail to preserve the accurate semantic similarities in binary code beyond keyword matching, especially on short texts. Here we propose a novel text hashing framework with convolutional neural networks. In particular, we first embed the keyword features into compact binary code with a locality preserving constraint. Meanwhile word features and position features are together fed into a convolutional network to learn the implicit features which are further incorporated with the explicit features to fit the pretrained binary code. Such base method can be successfully accomplished without any external tags/labels, and other three model variations are designed to integrate tags/labels. Experimental results show the superiority of our proposed approach over several state-of-the-art hashing methods when tested on one short text dataset as well as one normal text dataset.

Introduction

In large-scale similarity searches, such as finding near-duplicate articles or relevant web pages, raw text comparison is computationally prohibitive. Hashing techniques address this by mapping documents into short, fixed-length binary strings where semantic similarity is preserved in Hamming space.

Traditional hashing methods face two primary limitations. First, they often suffer from semantic blindness, relying on explicit features like Bag-of-Words or TF-IDF that fail when different words describe the same concept (e.g., "Obama" vs. "President"). Second, they exhibit context ignorance, as latent models like LDA or RBMs capture global semantics but ignore word order and local context. For instance, the word "code" functions differently as a noun than as a verb, yet traditional models treat them identically.

The THC Framework

To bridge these gaps, we propose Text Hashing with Convolutional Neural Networks (THC). This framework integrates traditional keyword features with deep semantic features learned via CNNs, capturing both word order and position information.

The overall architecture of the THC framework, illustrating the two-stage pipeline and the CNN components.

The Two-Stage Pipeline

The THC framework operates in two stages:

  1. Stage I (Binary Code Pre-training): The model generates target binary codes for training data using a locality-preserving constraint (Laplacian Eigenmaps). This ensures that documents with similar keyword distributions start with similar codes.
  2. Stage II (Hash Function Training): A CNN is trained to predict these binary codes from raw text. This stage can be unsupervised (THC-I) or supervised (THC-II through IV) by incorporating external tags.

CNN Architecture and Feature Fusion

The "secret sauce" of the THC architecture lies in its feature representation and fusion:

  • Word + Position Embeddings: Each word is represented by a pre-trained vector (e.g., GloVe). Crucially, we add position features—vectors representing the word's relative distance to the start and end of the text—to capture structural context.
  • Collapsing and Pooling: After a 1D convolution layer, a novel "collapsing" step compresses the interaction between word and position features before K-max-over-time pooling.
  • Hybrid Output: The final hash code is not derived from the CNN alone. The model integrates the CNN’s "implicit" semantic features with the document's "explicit" TF-IDF vector. This ensures the model retains the benefits of simple keyword matching while gaining deep semantic insight.

Experimental Results

We evaluated THC on two distinct datasets: SearchSnippets (12,340 short web snippets) and 20Newsgroups (18,846 longer forum posts). The primary metric was Mean Precision at 100 (mP@100).

Performance comparison (mP@100) of THC variants against state-of-the-art baselines across different bit lengths.

Key Insights

  • Superiority on Short Text: On SearchSnippets, the unsupervised THC-I outperformed the best unsupervised baseline (STH-RBF) by roughly 9-10%. The fully supervised THC-IV achieved 80.56% precision, compared to 71.09% for the best non-neural supervised baseline (TSH-KSH).
  • Scalability to Normal Text: On 20Newsgroups, the improvement was more modest (2-3%) but statistically significant, proving the model scales effectively to longer documents.
  • Implicit + Explicit = Better: Combining CNN features with TF-IDF vectors consistently yielded the best results. Additionally, adding position embeddings improved precision by 1-2%, confirming that word placement is a vital semantic signal.

Conclusion

The THC framework demonstrates that convolutional neural networks can significantly enhance text hashing by capturing context and word order. By fusing implicit and explicit features, the model achieves state-of-the-art performance across varying text lengths. Future work will explore deeper architectures and recurrent models to further improve semantic capture in long-form text.

Summary updated

BibTeX
@inproceedings{xu2015convolutional,
  author = {Jiaming Xu and Peng Wang and Guanhua Tian and Bo Xu and Jun Zhao and Fangyuan Wang and Hongwei Hao},
  title = {{Convolutional Neural Networks for Text Hashing}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2015},
  url = {https://openreview.net/forum?id=rkV9drfuWS},
}
Figure