# facebookresearch/fasttext architecture

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

- Interactive diagram: https://gitdiagram.com/facebookresearch/fasttext
- Repository: https://github.com/facebookresearch/fasttext

## Overview

fastText is a library and CLI for learning word representations and text classifiers, then querying or evaluating the resulting models. The main documented path is a user command routed by the CLI into the FastText engine, which trains or loads a model and produces vectors or predictions. Separate branches cover Python access, model compression, and bilingual embedding alignment. The README establishes the main use cases; edges from sampled code are limited to visible dispatch and module references, so unsampled internal call paths are omitted.

Main entry points: [`src/fasttext.cc`](https://github.com/facebookresearch/fasttext/blob/main/src/fasttext.cc) (FastText engine), [`src/main.cc`](https://github.com/facebookresearch/fasttext/blob/main/src/main.cc) (CLI commands), [`alignment/utils.py`](https://github.com/facebookresearch/fasttext/blob/main/alignment/utils.py) (Alignment utilities), [`python/fasttext_module/fasttext/FastText.py`](https://github.com/facebookresearch/fasttext/blob/main/python/fasttext_module/fasttext/FastText.py) (Python API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Core engine"]
  node_args["Arguments<br/>[args.cc]"]
  node_fasttext["FastText engine<br/>[fasttext.cc]"]
  node_dictionary["Dictionary<br/>[dictionary.cc]"]
  node_model["Training model<br/>[model.cc]"]
  node_loss["Training losses<br/>[loss.cc]"]
  node_matrices["Vector matrices<br/>[densematrix.cc]"]
  node_quantization["Model quantization<br/>[quantmatrix.cc]"]
end

subgraph group_interfaces["User interfaces"]
  node_cli["CLI commands<br/>[main.cc]"]
  node_python["Python API<br/>[FastText.py]"]
  node_pybind["Native binding<br/>[fasttext_pybind.cc]"]
  node_wasm["WebAssembly API<br/>[fasttext_wasm.cc]"]
  node_wasmjs["JavaScript wrapper<br/>[fasttext.js]"]
end

subgraph group_alignment["Embedding alignment"]
  node_supervised_align["Supervised alignment<br/>[align.py]"]
  node_unsup_align["Unsupervised alignment<br/>[unsup_align.py]"]
  node_multi_align["Multilingual alignment"]
  node_alignment_utils["Alignment utilities<br/>[utils.py]"]
end

subgraph group_utilities["Model utilities"]
  node_py_util["Python utilities<br/>[util.py]"]
end

node_user(("User"))
node_model_file["Model files"]
node_text_data["Training text"]
node_embeddings["Embedding files"]

node_user -->|"runs command"| node_cli
node_cli -->|"dispatches"| node_fasttext
node_cli -.->|"parses options"| node_args
node_text_data -->|"trains from"| node_fasttext
node_fasttext -->|"saves or loads"| node_model_file
node_fasttext -->|"exports vectors"| node_embeddings
node_fasttext -.->|"uses vocabulary"| node_dictionary
node_fasttext -.->|"optimizes model"| node_model
node_fasttext -.->|"creates loss"| node_loss
node_fasttext -.->|"uses matrices"| node_matrices
node_fasttext -.->|"quantizes model"| node_quantization
node_python -.->|"calls native API"| node_pybind
node_wasmjs -.->|"calls bindings"| node_wasm
node_supervised_align -->|"loads and evaluates"| node_alignment_utils
node_unsup_align -->|"uses helpers"| node_alignment_utils
node_multi_align -->|"uses helpers"| node_alignment_utils
node_python -.->|"offers utilities"| node_py_util

click node_cli "https://github.com/facebookresearch/fasttext/blob/main/src/main.cc"
click node_args "https://github.com/facebookresearch/fasttext/blob/main/src/args.cc"
click node_fasttext "https://github.com/facebookresearch/fasttext/blob/main/src/fasttext.cc"
click node_dictionary "https://github.com/facebookresearch/fasttext/blob/main/src/dictionary.cc"
click node_model "https://github.com/facebookresearch/fasttext/blob/main/src/model.cc"
click node_loss "https://github.com/facebookresearch/fasttext/blob/main/src/loss.cc"
click node_matrices "https://github.com/facebookresearch/fasttext/blob/main/src/densematrix.cc"
click node_quantization "https://github.com/facebookresearch/fasttext/blob/main/src/quantmatrix.cc"
click node_python "https://github.com/facebookresearch/fasttext/blob/main/python/fasttext_module/fasttext/FastText.py"
click node_pybind "https://github.com/facebookresearch/fasttext/blob/main/python/fasttext_module/fasttext/pybind/fasttext_pybind.cc"
click node_wasm "https://github.com/facebookresearch/fasttext/blob/main/webassembly/fasttext_wasm.cc"
click node_wasmjs "https://github.com/facebookresearch/fasttext/blob/main/webassembly/fasttext.js"
click node_supervised_align "https://github.com/facebookresearch/fasttext/blob/main/alignment/align.py"
click node_unsup_align "https://github.com/facebookresearch/fasttext/blob/main/alignment/unsup_align.py"
click node_multi_align "https://github.com/facebookresearch/fasttext/blob/main/alignment/unsup_multialign.py"
click node_alignment_utils "https://github.com/facebookresearch/fasttext/blob/main/alignment/utils.py"
click node_py_util "https://github.com/facebookresearch/fasttext/blob/main/python/fasttext_module/fasttext/util/util.py"

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_args,node_fasttext,node_dictionary,node_model,node_loss,node_matrices,node_quantization,node_user toneBlue
class node_cli,node_python,node_pybind,node_wasm,node_wasmjs toneAmber
class node_supervised_align,node_unsup_align,node_multi_align,node_alignment_utils toneMint
class node_py_util toneRose
class node_model_file,node_text_data,node_embeddings toneIndigo
```

## Components

### Core engine

- [Arguments](https://github.com/facebookresearch/fasttext/blob/main/src/args.cc): `src/args.cc`
- [FastText engine](https://github.com/facebookresearch/fasttext/blob/main/src/fasttext.cc): `src/fasttext.cc`
- [Dictionary](https://github.com/facebookresearch/fasttext/blob/main/src/dictionary.cc): `src/dictionary.cc`
- [Training model](https://github.com/facebookresearch/fasttext/blob/main/src/model.cc): `src/model.cc`
- [Training losses](https://github.com/facebookresearch/fasttext/blob/main/src/loss.cc): `src/loss.cc`
- [Vector matrices](https://github.com/facebookresearch/fasttext/blob/main/src/densematrix.cc): `src/densematrix.cc`
- [Model quantization](https://github.com/facebookresearch/fasttext/blob/main/src/quantmatrix.cc): `src/quantmatrix.cc`

### User interfaces

- [CLI commands](https://github.com/facebookresearch/fasttext/blob/main/src/main.cc): `src/main.cc`
- [Python API](https://github.com/facebookresearch/fasttext/blob/main/python/fasttext_module/fasttext/FastText.py): `python/fasttext_module/fasttext/FastText.py`
- [Native binding](https://github.com/facebookresearch/fasttext/blob/main/python/fasttext_module/fasttext/pybind/fasttext_pybind.cc): `python/fasttext_module/fasttext/pybind/fasttext_pybind.cc`
- [WebAssembly API](https://github.com/facebookresearch/fasttext/blob/main/webassembly/fasttext_wasm.cc): `webassembly/fasttext_wasm.cc`
- [JavaScript wrapper](https://github.com/facebookresearch/fasttext/blob/main/webassembly/fasttext.js): `webassembly/fasttext.js`

### Embedding alignment

- [Supervised alignment](https://github.com/facebookresearch/fasttext/blob/main/alignment/align.py): `alignment/align.py`
- [Unsupervised alignment](https://github.com/facebookresearch/fasttext/blob/main/alignment/unsup_align.py): `alignment/unsup_align.py`
- [Multilingual alignment](https://github.com/facebookresearch/fasttext/blob/main/alignment/unsup_multialign.py): `alignment/unsup_multialign.py`
- [Alignment utilities](https://github.com/facebookresearch/fasttext/blob/main/alignment/utils.py): `alignment/utils.py`

### Model utilities

- [Python utilities](https://github.com/facebookresearch/fasttext/blob/main/python/fasttext_module/fasttext/util/util.py): `python/fasttext_module/fasttext/util/util.py`

### Other components

- **User**
- **Model files**
- **Training text**
- **Embedding files**

## Connections

- User → CLI commands: runs command
- CLI commands → FastText engine: dispatches (evidence: `src/main.cc`)
- CLI commands → Arguments: parses options
- Training text → FastText engine: trains from
- FastText engine → Model files: saves or loads
- FastText engine → Embedding files: exports vectors
- FastText engine → Dictionary: uses vocabulary
- FastText engine → Training model: optimizes model
- FastText engine → Training losses: creates loss
- FastText engine → Vector matrices: uses matrices
- FastText engine → Model quantization: quantizes model
- Python API → Native binding: calls native API
- JavaScript wrapper → WebAssembly API: calls bindings
- Supervised alignment → Alignment utilities: loads and evaluates (evidence: `alignment/align.py`)
- Unsupervised alignment → Alignment utilities: uses helpers (evidence: `alignment/unsup_align.py`)
- Multilingual alignment → Alignment utilities: uses helpers (evidence: `alignment/unsup_multialign.py`)
- Python API → Python utilities: offers utilities
