This repository contains FastText word embedding models that have been converted
from the original .vec format to ONNX format for efficient deployment and
inference.
These models provide semantic word embeddings for use in spell checking and natural language processing applications.
The FastText ONNX models serve as a semantic similarity backend for the Kotoshu spell checker. They enable:
-
Semantic word similarity calculations
-
Context-aware spelling suggestions
-
Cross-language semantic comparisons
-
Efficient inference via ONNX Runtime
-
Multi-language Support: Models for 6 languages (de, en, es, fr, pt, ru)
-
Optimized Format: 37x compression from original FastText vectors
-
ONNX Compatible: Works with onnxruntime 1.23.2+
-
High Quality: 100K vocabulary per language with 300-dimensional embeddings
-
Easy Integration: Drop-in compatibility with Kotoshu spell checker
| Language | Code | Vocab Size | Embedding Dim | Model Size | Source |
|---|---|---|---|---|---|
German |
de |
100,000 |
300D |
114.44 MB |
|
English |
en |
100,000 |
300D |
114.44 MB |
|
Spanish |
es |
100,000 |
300D |
114.44 MB |
|
French |
fr |
100,000 |
300D |
114.44 MB |
|
Portuguese |
pt |
100,000 |
300D |
114.44 MB |
|
Russian |
ru |
100,000 |
300D |
114.44 MB |
-
ONNX IR Version: 11
-
ONNX Opset Version: 11
-
Compatibility: onnxruntime 1.23.2+
-
Input:
word_index(int64, shape=[1]) -
Output:
embedding(float32, shape=[300])
The ONNX models use a simple embedding lookup architecture:
-
Constant Node: Contains the embedding matrix (vocab_size x 300)
-
Gather Node: Retrieves the embedding for a given word index
-
Squeeze Node: Removes the batch dimension
word_index (int64[1]) → Gather → Squeeze → embedding (float32[300])
↓
Embeddings Matrix (Constant)import onnxruntime as ort
import numpy as np
# Load model
sess = ort.InferenceSession('models/en/fasttext.en.onnx')
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name
# Get embedding for word index
word_index = 0 # Replace with actual word index from vocabulary
embedding = sess.run([output_name], {input_name: np.array([word_index], dtype=np.int64)})[0]
print(f"Embedding shape: {embedding.shape}") # (300,)
print(f"Embedding: {embedding}")require 'kotoshu'
# Get ONNX model (downloads or converts as needed)
cache = Kotoshu::Cache::ModelCache.new
onnx_path = cache.get_onnx_model('en')
# Use for semantic similarity
# (This feature is planned for future Kotoshu versions)Each model includes metadata in models/{lang}/metadata.json:
{
"version": "2026-02-08T04:25:31Z",
"language": "en",
"type": "onnx",
"file": "fasttext.en.onnx",
"checksum": "sha256_hash",
"source_model": "cc.en.300.vec",
"conversion_method": "fasttext_to_onnx.py",
"opset_version": 11,
"vocab_size": 100000,
"embedding_dim": 300
}All models have been functionally verified:
# Run verification tests
ruby scripts/verify_all_models.rb
# Test individual model
python3 scripts/test_onnx.py enModels can be downloaded directly from the Releases page.
Kotoshu will automatically download and cache these models when needed:
# Ruby API
cache = Kotoshu::Cache::ModelCache.new
onnx_path = cache.get_onnx_model('de')If you want to convert the models yourself from FastText .vec files:
pip install onnx onnxruntime numpy# Download FastText vectors
wget https://dl.fbaipublicfiles.com/fasttext/vectors-crawl/cc.en.300.vec.gz
gunzip cc.en.300.vec.gz
# Convert to ONNX
python3 scripts/fasttext_to_onnx.py cc.en.300.vec models/en/fasttext.en.onnx --vocab-size 100000The repository includes several utility scripts:
-
scripts/fasttext_to_onnx.py- Convert FastText.vecfiles to ONNX format -
scripts/test_onnx.py- Test a single ONNX model -
scripts/verify_all_models.rb- Verify all models for functionality
# Convert a FastText model to ONNX
python3 scripts/fasttext_to_onnx.py <vec_file> <output_onnx> [--vocab-size N]
# Example
python3 scripts/fasttext_to_onnx.py cc.en.300.vec models/en/fasttext.en.onnx --vocab-size 100000These models are derived from the FastText pretrained vectors, which are licensed under the Creative Commons Attribution-Share-Alike License 3.0.
These models are derived from the FastText pretrained word vectors, which were trained on Common Crawl data by Facebook AI Research.
If you use these models, please cite the original FastText paper:
@inproceedings{bojar-2018-find,
title = "Findings of the 2018 Conference on Machine Translation ({WMT}18)",
author = "Bojar, Ond{\v{r}}ej and
Federmann, Christian and
Fishel, Mark and
Graham, Yvette and
Haddow, Barry and
Huck, Matthias and
Koehn, Philipp",
booktitle = "Proceedings of the Third Conference on Machine Translation: Shared Task Papers",
month = oct,
year = "2018",
address = "Belgium, Brussels",
publisher = "Association for Computational Linguistics",
url = "https://www.aclweb.org/anthology/W18-6401",
doi = "10.18653/v1/W18-6401",
pages = "272--303",
}-
FastText - Facebook’s library for efficient learning of word representations
-
ONNX - Open Neural Network Exchange
-
ONNX Runtime - Microsoft’s cross-platform inference engine
-
Kotoshu - Spell checker library
See CONTRIBUTING.md for guidelines on contributing to this repository.
Contributions are welcome for:
-
Adding new language models
-
Improving conversion scripts
-
Bug fixes and optimizations
-
Documentation improvements
-
Issues: GitHub Issues
-
Documentation: Kotoshu Documentation