Parallelizing Word2Vec in Multi-Core and Many-Core Architectures

Shihao Ji, Nadathur Satish, Sheng Li, Pradeep Dubey · DOI

Abstract

Word2vec is a widely used algorithm for extracting low-dimensional vector representations of words. State-of-the-art algorithms including those by Mikolov et al. have been parallelized for multi-core CPU architectures, but are based on vector-vector operations with "Hogwild" updates that are memory-bandwidth intensive and do not efficiently use computational resources. In this paper, we propose "HogBatch" by improving reuse of various data structures in the algorithm through the use of minibatching and negative sample sharing, hence allowing us to express the problem using matrix multiply operations. We also explore different techniques to distribute word2vec computation across nodes in a compute cluster, and demonstrate good strong scalability up to 32 nodes. The new algorithm is particularly suitable for modern multi-core/many-core architectures, especially Intel's latest Knights Landing processors, and allows us to scale up the computation near linearly across cores and nodes, and process hundreds of millions of words per second, which is the fastest word2vec implementation to the best of our knowledge.

Introduction: The Bottleneck in Word Embeddings

Word2Vec has become a foundational tool in natural language processing for generating dense word embeddings. However, traditional implementations, such as the original Google version, rely on the Hogwild! approach—a lock-free parallel Stochastic Gradient Descent (SGD). While Hogwild! allows multiple threads to update a shared model, it suffers from two critical hardware-level bottlenecks on modern architectures. First, it relies on Level-1 BLAS vector-vector operations, which are memory-bound; the CPU spends more time fetching data than computing. Second, high thread counts lead to cache line "ping-ponging" as multiple cores attempt to update the same memory locations simultaneously, severely limiting scalability.

Methods: From Hogwild to HogBatch

To address these limitations, we introduce HogBatch, a redesign that shifts Word2Vec from a memory-bound to a compute-bound workload. The core innovation involves two techniques: mini-batching and negative sample sharing.

In standard Word2Vec, each input word is processed individually with its own set of negative samples. HogBatch instead groups multiple input words into a mini-batch and shares a single set of negative samples across that entire batch. This algorithmic shift allows the core mathematical operations to be expressed as General Matrix Multiplication (GEMM), or Level-3 BLAS operations.

Comparison of the original dot-product based Word2Vec versus the proposed SGEMM-based HogBatch approach.

By utilizing GEMM, the algorithm can leverage high-performance vector units (such as AVX-512) and maintain data in local registers for longer periods. Furthermore, by aggregating updates within a mini-batch before writing them back to the main model, HogBatch significantly reduces the frequency of conflicting updates between cores.

Evaluation Framework

The performance and quality of HogBatch were evaluated using the following:

  • Training Corpus: The One Billion Word Benchmark.
  • Quality Benchmarks: WS-353 for word similarity and the Google word analogy benchmark to ensure embedding quality remained high despite algorithmic approximations.
  • Vocabulary: 1.1 million words with 300-dimensional vectors.

Key Insights

  • Architectural Optimization: Moving from Level-1 to Level-3 BLAS is the primary driver of performance. Matrix multiplication is highly optimized on modern hardware, and restructuring the algorithm to fit this pattern unlocks significant throughput.
  • Algorithmic Approximation: Sharing negative samples is a departure from the original algorithm. However, empirical results show that this change has a negligible impact on embedding accuracy while providing a massive boost in computational efficiency.
  • Reduced Contention: Aggregating updates locally within threads before global synchronization mitigates the "ping-pong" effect in the cache hierarchy.

Key Results

HogBatch demonstrates superior performance across various hardware configurations. On a 36-core Intel Xeon (Broadwell) node, it achieved 5.8 million words per second, a 3.6x improvement over the original implementation. On the many-core Intel Xeon Phi (Knights Landing), throughput reached 8.9 million words per second on a single chip.

Throughput comparison showing near-linear scaling of the HogBatch implementation compared to the original Word2Vec as the number of threads increases.

Furthermore, the implementation scales efficiently in distributed environments. A 4-node cluster of Xeon Phi processors reached 29.4 million words per second, outperforming reported GPU-based clusters. The system maintains near-linear scaling up to 16 nodes and remains highly competitive up to 32 nodes.

Conclusion and Future Work

HogBatch represents a significant step forward in high-performance word embedding training. By aligning the algorithm with the strengths of modern multi-core and many-core hardware, we achieved record-breaking throughput without sacrificing model quality. Future research will focus on optimizing convergence at extreme scales (32+ nodes) and exploring the impact of very large mini-batches on specialized or smaller datasets.

Summary updated

BibTeX
@misc{ji2016parallelizing,
  author = {Shihao Ji and Nadathur Satish and Sheng Li and Pradeep Dubey},
  title = {{Parallelizing Word2Vec in Multi-Core and Many-Core Architectures}},
  year = {2016},
  eprint = {1611.06172},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1611.06172},
}
Figure