chrisjmccormick/word2vec_commented
FreeCommented (but unaltered) version of original word2vec C implementation.
FreeFree tier
Inputs: text
About chrisjmccormick/word2vec_commented
Commented version of Google's original word2vec C implementation. Includes detailed source comments for the skip-gram and CBOW architectures with negative sampling (word2vec.c), as well as the word2phrase.c tool for phrase detection. The code is functionally unaltered from the original, making it a learning resource for understanding word2vec training. Also includes vocabulary construction code with hash table, demo scripts, and evaluation datasets (questions-words.txt, questions-phrases.txt).
Key Features
Annotated source code for word2vec.c covering skip-gram and CBOW with negative sampling
Annotated word2phrase.c tool for phrase detection (e.g., New_York → New_York_City)
Functionally unaltered from Google's original release
Includes vocabulary construction with hash table for fast lookup
Supports both skip-gram and CBOW model architectures
Provides demo scripts (demo-word.sh, demo-phrases.sh) and evaluation datasets
Multi-threaded training via TrainModelThread function
Includes distance.c, word-analogy.c, compute-accuracy.c for evaluation
Pros & Cons
Pros
- Well-commented code makes complex concepts accessible to learners
- Functionally identical to original, ensuring correctness
- Covers both skip-gram and CBOW with negative sampling in one codebase
- Includes phrase detection tool (word2phrase.c) and demo scripts
- Free and open source under a permissive license
Cons
- Does not include comments for Hierarchical Softmax (only negative sampling)
- Limited to C implementation; no Python version available
- Requires understanding of C programming and word2vec basics
- No built-in text tokenization; expects preprocessed whitespace-separated text
- Testing code (e.g., distance.c, word-analogy.c) is not commented
- Only covers training code thoroughly; evaluation code has minimal comments
Best For
Learning and understanding word2vec implementation detailsEducational reference for NLP practitioners and studentsTeaching skip-gram and CBOW architectures with negative samplingUnderstanding phrase detection in word2vecResearch on word embeddings and vector representations
FAQ
What is this repository?
It is a functionally unaltered version of Google's word2vec C implementation with added source comments for learning purposes.
Which architectures are commented?
Skip-gram and CBOW architectures with negative sampling are commented in word2vec.c.
Does it include Hierarchical Softmax?
No, Hierarchical Softmax is not yet commented for either architecture.
Is the code altered in any way?
No, the code is functionally unaltered from Google's original release; only comments are added.
What other files are commented?
word2phrase.c for phrase detection is also commented.
What input format does word2vec expect?
The code expects a training file with words separated by whitespace, one sentence per line (sentences separated by newline).