Abstract
Word2Vec is a widely used algorithm for extracting low-dimensional vector representations of words. It generated considerable excitement in the machine learning and natural language processing (NLP) communities recently due to its exceptional performance in many NLP applications such as named entity recognition, sentiment analysis, machine translation and question answering. 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 that are memory-bandwidth intensive and do not efficiently use computational resources. In this paper, we improve reuse of various data structures in the algorithm through the use of minibatching, 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. In combination, these techniques allow 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.
1. Introduction
Word2Vec has become a cornerstone of modern Natural Language Processing (NLP), enabling low-dimensional vector representations that capture semantic relationships. However, training on massive datasets remains computationally expensive. The original implementation by Mikolov et al. utilizes Hogwild SGD, allowing lock-free updates across multiple threads. While effective, this approach is limited by memory bandwidth and cache inefficiency. Modern CPUs often stall while waiting for data for simple vector-vector dot products, leaving compute units underutilized.
2. Methods: From Dot Products to Matrix Multiplies
To address these bottlenecks, we propose a fundamental shift in the computational kernel of Word2Vec. The primary goal is to move the bottleneck from memory bandwidth to raw compute power.
2.1 Minibatching and Negative Sample Sharing
In the standard Skip-gram model with negative sampling, each input word is contrasted against a unique set of negative samples. We introduce a minibatching strategy where negative samples are shared across a batch of input words. This structural change allows us to aggregate multiple independent dot products into a single Single-precision General Matrix Multiply (SGEMM) operation.
By utilizing Level-3 BLAS operations, we significantly increase arithmetic intensity. The processor reads a vector once and reuses it for multiple calculations within the matrix multiply, effectively mitigating the "cache ping-ponging" issue inherent in Hogwild and allowing the code to scale better as more CPU cores are added.
2.2 Distributed Data Parallelism
Scaling beyond a single node requires efficient synchronization. We implement a frequency-aware synchronization scheme for distributed clusters. Recognizing that word updates follow a power-law distribution (Zipf's Law), we synchronize "hot" (frequently occurring) word vectors more often than rare ones, drastically reducing network overhead without sacrificing model accuracy.
3. Experimental Evaluation
We evaluated our implementation on three corpora: Text8 (17M words), the One Billion Word Benchmark, and a 7.2B word aggregate collection. Accuracy was validated using the WS-353 word similarity task and the Google analogy dataset.
3.1 Performance Results
On a dual-socket Intel Xeon (Broadwell) node, our SGEMM-optimized code achieved 5.8 million words/sec, a 3.6x improvement over the original implementation. On an Intel Xeon Phi (Knights Landing), performance reached 8.9 million words/sec.
Furthermore, the system demonstrated near-linear strong scalability. By distributing the workload across 32 nodes, we achieved a processing rate exceeding 100 million words per second, representing the fastest known Word2Vec implementation to date.
4. Conclusion
By re-architecting Word2Vec to leverage high-performance matrix operations and intelligent distributed synchronization, we have significantly reduced training times for large-scale embeddings. Future work will explore asynchronous parameter server models and adaptive learning rate schedules to further enhance scalability on even larger clusters.
Summary updated