Skip to main content

A set of tools to compress gensim fasttext models

Project description


This Python 3 package allows to compress fastText word embedding models (from the gensim package) by orders of magnitude, without seriously affecting their quality. It can be installed with pip:

pip install compress-fasttext

This blogpost (in Russian) gives more details about the motivation and methods for compressing fastText models.

Model compression

You can use this package to compress your own fastText model (or one downloaded e.g. from RusVectores):

import gensim
import compress_fasttext
big_model = gensim.models.fasttext.FastTextKeyedVectors.load('path-to-original-model')
small_model = compress_fasttext.prune_ft_freq(big_model, pq=True)'path-to-new-model')

Different compression methods include:

  • matrix decomposition (svd_ft)
  • product quantization (quantize_ft)
  • optimization of feature hashing (prune_ft)
  • feature selection (prune_ft_freq)

The recommended approach is combination of feature selection and quantization (prune_ft_freq with pq=True).

Model usage

If you just need a tiny fastText model for Russian, you can download this 28-megabyte model. It's a compressed version of ruscorpora_none_fasttextskipgram_300_2_2019 model from RusVectores.

If compress-fasttext is already installed, you can download and use this tiny model

import compress_fasttext
small_model = compress_fasttext.models.CompressedFastTextKeyedVectors.load(

The class CompressedFastTextKeyedVectors inherits from gensim.models.keyed_vectors.FastTextKeyedVectors, but makes a few additional optimizations.


This code is heavily based on the navec package by Alexander Kukushkin and the blogpost by Andrey Vasnetsov about shrinking fastText embeddings.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

compress-fasttext-0.0.4.tar.gz (8.1 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page