# shimingyoung/word2vec architecture

> Architecture diagram of the GitHub repository shimingyoung/word2vec, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shimingyoung/word2vec
- Repository: https://github.com/shimingyoung/word2vec

## Overview

This is the word2vec toolkit: it optionally forms phrases from corpus text, trains CBOW or Skip-gram word embeddings, and provides tools to explore similarities, solve analogies, and evaluate analogy accuracy. The core training code also builds vocabulary, supports hierarchical softmax and negative sampling, and can emit word clusters. The map focuses on runtime tools and their file-based inputs and outputs; relationships come from the README or sampled source excerpts. Demo scripts are not mapped as runtime components.

Main entry points: [`word2vec.c`](https://github.com/shimingyoung/word2vec/blob/master/word2vec.c) (Embedding trainer), [`word2phrase.c`](https://github.com/shimingyoung/word2vec/blob/master/word2phrase.c) (Phrase detection), [`compute-accuracy.c`](https://github.com/shimingyoung/word2vec/blob/master/compute-accuracy.c) (Analogy accuracy), [`distance.c`](https://github.com/shimingyoung/word2vec/blob/master/distance.c) (Similarity search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_prep["Text preparation"]
  node_phrase["Phrase detection<br/>[word2phrase.c]"]
  node_phrased_corpus["Phrase corpus"]
end

subgraph group_training["Embedding training"]
  node_vocabulary["Vocabulary building<br/>[word2vec.c]"]
  node_trainer["Embedding trainer<br/>[word2vec.c]"]
  node_vectors["Word vectors"]
  node_clusters["Word clusters"]
end

subgraph group_exploration["Vector exploration"]
  node_similarity["Similarity search<br/>[distance.c]"]
  node_analogy["Analogy search<br/>[word-analogy.c]"]
end

subgraph group_evaluation["Model evaluation"]
  node_accuracy["Analogy accuracy<br/>[compute-accuracy.c]"]
end

node_user(("User"))
node_corpus["Text corpus"]
node_questions["Analogy questions"]

node_user -->|"runs"| node_phrase
node_corpus -->|"reads"| node_phrase
node_phrase -->|"writes"| node_phrased_corpus
node_user -->|"configures"| node_trainer
node_corpus -->|"reads"| node_vocabulary
node_trainer -->|"builds"| node_vocabulary
node_trainer -->|"writes"| node_vectors
node_trainer -->|"writes"| node_clusters
node_user -->|"queries"| node_similarity
node_vectors -->|"reads"| node_similarity
node_user -->|"queries"| node_analogy
node_vectors -->|"reads"| node_analogy
node_user -->|"runs"| node_accuracy
node_vectors -->|"reads"| node_accuracy
node_questions -->|"supplies"| node_accuracy

click node_phrase "https://github.com/shimingyoung/word2vec/blob/master/word2phrase.c"
click node_vocabulary "https://github.com/shimingyoung/word2vec/blob/master/word2vec.c"
click node_trainer "https://github.com/shimingyoung/word2vec/blob/master/word2vec.c"
click node_similarity "https://github.com/shimingyoung/word2vec/blob/master/distance.c"
click node_analogy "https://github.com/shimingyoung/word2vec/blob/master/word-analogy.c"
click node_accuracy "https://github.com/shimingyoung/word2vec/blob/master/compute-accuracy.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_phrase,node_phrased_corpus,node_user toneBlue
class node_vocabulary,node_trainer,node_vectors,node_clusters toneAmber
class node_similarity,node_analogy toneMint
class node_accuracy toneRose
class node_corpus,node_questions toneIndigo
```

## Components

### Text preparation

- [Phrase detection](https://github.com/shimingyoung/word2vec/blob/master/word2phrase.c): `word2phrase.c`
- **Phrase corpus**

### Embedding training

- [Vocabulary building](https://github.com/shimingyoung/word2vec/blob/master/word2vec.c): `word2vec.c`
- [Embedding trainer](https://github.com/shimingyoung/word2vec/blob/master/word2vec.c): `word2vec.c`
- **Word vectors**
- **Word clusters**

### Vector exploration

- [Similarity search](https://github.com/shimingyoung/word2vec/blob/master/distance.c): `distance.c`
- [Analogy search](https://github.com/shimingyoung/word2vec/blob/master/word-analogy.c): `word-analogy.c`

### Model evaluation

- [Analogy accuracy](https://github.com/shimingyoung/word2vec/blob/master/compute-accuracy.c): `compute-accuracy.c`

### Other components

- **User**
- **Text corpus**
- **Analogy questions**

## Connections

- User → Phrase detection: runs (evidence: `word2phrase.c`)
- Text corpus → Phrase detection: reads (evidence: `word2phrase.c`)
- Phrase detection → Phrase corpus: writes (evidence: `word2phrase.c`)
- User → Embedding trainer: configures (evidence: `README.txt`)
- Text corpus → Vocabulary building: reads (evidence: `word2vec.c`)
- Embedding trainer → Vocabulary building: builds (evidence: `word2vec.c`)
- Embedding trainer → Word vectors: writes (evidence: `word2vec.c`)
- Embedding trainer → Word clusters: writes (evidence: `word2vec.c`)
- User → Similarity search: queries (evidence: `distance.c`)
- Word vectors → Similarity search: reads (evidence: `distance.c`)
- User → Analogy search: queries (evidence: `word-analogy.c`)
- Word vectors → Analogy search: reads (evidence: `word-analogy.c`)
- User → Analogy accuracy: runs (evidence: `compute-accuracy.c`)
- Word vectors → Analogy accuracy: reads (evidence: `compute-accuracy.c`)
- Analogy questions → Analogy accuracy: supplies (evidence: `compute-accuracy.c`)
