Registry / ai-ml / fasttext-wheel

fasttext-wheel

JSON →
library0.9.2pypypi✓ verified 52d ago

FastText is an open-source, lightweight library developed by Facebook AI Research for efficient learning of word embeddings and text classification. The `fasttext-wheel` package provides pre-compiled Python bindings for the core FastText C++ library, streamlining installation. The current version is 0.9.2, with releases being somewhat infrequent but active, focusing on core improvements and broader access.

ai-ml
pip install fasttext-wheel
Install & Compatibility
Where this runs
tested against v0.9.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 3.85s
py 3.11
✕ build_error
✓ 3.68s
py 3.12
✕ build_error
✓ 4.23s
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 4.45s
109MB installed
● package 109MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fasttext
import fasttext
from fastText import fastText
Prior to v0.9.1, the official GitHub module used 'from fastText import fastText'. The current consolidated module is 'fasttext'.

This quickstart demonstrates how to train a supervised text classification model, make predictions, and save/load the model. It uses a dynamically created dummy dataset formatted as required by FastText.

import fasttext import os # Create a dummy training data file (replace with your actual data) # Format: __label__label1 text1 # __label__label2 text2 train_file = "train.txt" with open(train_file, "w") as f: f.write("__label__positive this movie is great\n") f.write("__label__negative this movie is terrible\n") f.write("__label__positive i love this film\n") f.write("__label__negative what a waste of time\n") # Train a supervised text classification model # Adjust parameters like epoch, lr, wordNgrams for your specific task model = fasttext.train_supervised(input=train_file, epoch=25, lr=1.0, wordNgrams=2) # Predict labels for new text print("Prediction for 'this movie is wonderful':", model.predict("this movie is wonderful")) print("Prediction for 'worst movie ever':", model.predict("worst movie ever")) # Optionally save and load the model model_path = "model.bin" model.save_model(model_path) loaded_model = fasttext.load_model(model_path) print("Loaded model prediction:", loaded_model.predict("this film is amazing")) # Clean up dummy file os.remove(train_file) os.remove(model_path)
fasttext --version
Debug
Known issues
breakingThe v0.9.1 release consolidated the official GitHub `fastText` module and the unofficial PyPI `fasttext` module. Users migrating from the *old official GitHub module* (which might have used `import fastText`) must now use `import fasttext`.
fix
Update your import statements from `from fastText import fastText` or similar to `import fasttext`.
affects: >=0.9.1
gotchaSupervised learning (`train_supervised`) requires input data to be formatted with `__label__` prefixes. Each line must contain `__label__<label_name> <text_content>`.
fix
Ensure your training data file adheres to the `__label__` format for each line. E.g., `__label__pos This is a positive review.`
affects: All versions
gotchaThe `model.predict()` method returns a tuple containing two lists: `([['label']], [array([probability])])`. Users often incorrectly expect a single string or float.
fix
Access the predicted label using `result[0][0][0]` and probability using `result[1][0][0]` for single-label, single-input predictions.
affects: All versions
gotchaFastText models, especially with large vocabularies or many n-grams, can consume significant amounts of RAM during training and when loaded, potentially leading to out-of-memory errors on systems with limited resources.
fix
Monitor memory usage; consider reducing `wordNgrams` or `dim`, or use `quantize_model()` for smaller memory footprint models post-training.
affects: All versions
deprecatedThe v0.2.0 release introduced a 'beta C++ API', deprecating some methods and moving functionality. While primarily a C++ change, it signaled potential future changes in Python binding behavior or available methods.
fix
Always refer to the latest official Python documentation for current API methods. If using older versions, be aware of potential method deprecation/removal.
affects: 0.2.0-0.9.0
Errors
Common errors & fixes
ERROR: Failed building wheel for fasttext
The `fasttext` package (as opposed to `fasttext-wheel`) attempts to compile C++ code from source during installation, but the necessary C++ build tools (like GCC on Linux/macOS or Visual C++ Build Tools on Windows) are either missing, outdated, or incompatible with the Python version, causing the build process to fail.
fix
Install the pre-compiled wheel package: `pip install fasttext-wheel`. If you still need to build from source, ensure you have the correct C++ build tools for your operating system and Python version (e.g., `sudo apt-get install build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, or Visual C++ Build Tools for Visual Studio on Windows).
ModuleNotFoundError: No module named 'fasttext'
This error occurs because the `fasttext` library was not installed correctly, or the Python environment where the code is run does not have `fasttext-wheel` installed. It can also be caused by a user's Python script being accidentally named `fasttext.py`, which shadows the actual installed library.
fix
First, ensure `fasttext-wheel` is installed in your active Python environment using `pip install fasttext-wheel`. If the error persists, check your current working directory and Python path for any files or folders named `fasttext.py` or `fasttext` that might conflict with the installed package, and rename them if found.
AttributeError: module 'fasttext' has no attribute 'train_supervised'
This typically indicates an incomplete or corrupted `fasttext` installation, often resulting from a failed source compilation if the `fasttext` package was installed instead of `fasttext-wheel`. It can also occur if a local script or module named `fasttext.py` is inadvertently imported instead of the official library, or if there's confusion with the API of other FastText wrappers like those in `gensim`.
fix
Uninstall any existing `fasttext` installations (`pip uninstall fasttext fasttext-wheel`) and then reinstall the pre-compiled wheel package: `pip install fasttext-wheel`. Verify that no local files named `fasttext.py` are present in your project directory.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte
FastText is designed to work with UTF-8 encoded text. This error occurs when processing input text files (for training or loading models) that are not UTF-8 encoded, or contain characters that cannot be decoded as UTF-8.
fix
Ensure all input text files are saved with UTF-8 encoding. You can convert existing files to UTF-8 using a text editor (by selecting 'Save As' and choosing UTF-8) or command-line tools like `iconv` (e.g., `iconv -f LATIN1 -t UTF-8 input.txt > output.txt`). If the issue occurs during model loading, verify the model file itself is not corrupted or was not saved with an incompatible encoding.
Upgrade
Version history
0.9.2latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
4
claudebot
4
ahrefsbot
3
seranking-bot
3
Amazon
1
amazonbot
1
Resources