Registry / ai-ml / fasttext-numpy2

fasttext-numpy2

JSON →
library0.10.4pypypi✓ verified 91d ago

fasttext-numpy2 is a Python library that provides bindings for Facebook AI Research's fastText, focusing on compatibility with NumPy 2.x. The original fastText library is designed for efficient learning of word representations and sentence classification. This `fasttext-numpy2` fork specifically addresses a critical breaking change introduced by NumPy 2.0, allowing users to continue using fastText with newer NumPy versions. The current version is 0.10.4, and its release cadence is primarily driven by maintaining compatibility with its dependencies, especially NumPy.

pip install fasttext-numpy2
INSTALL
IMPORT
SIG · FASTTEXT-NUMPY2
F
fasttext-numpy2
ai-mlpythonv0.10.4
Install
4.3s avg
Import
293ms
Disk
108MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.10.4 · 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
py 3.10–3.920 runs
build_error
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 4.3s · import 0.293s · 103MB
108MB installed
● package 108MB
Code
Verified usage

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

fasttext
✓ import fasttext
The official fastText Python module on PyPI uses the lowercase 'fasttext' import name, merging with previous unofficial versions.

This quickstart demonstrates how to train a simple text classification model using `fasttext-numpy2` and then make a prediction. It first creates a dummy dataset in a file named `data.txt` in the format expected by fastText for supervised learning. It then trains a model using `train_supervised` and finally predicts the label for a new piece of text.

import fasttext import os # Create a dummy training data file with open('data.txt', 'w') as f: f.write('__label__sports This is a great game.\n') f.write('__label__politics The election results are in.\n') f.write('__label__sports I love playing basketball.\n') f.write('__label__politics Debates are important for democracy.\n') # Train a supervised model model = fasttext.train_supervised('data.txt', epoch=5, lr=0.1, dim=100) # Predict a label for a new text text_to_predict = 'I watched a thrilling football match.' labels, probabilities = model.predict(text_to_predict) print(f"Text: '{text_to_predict}'") print(f"Predicted label: {labels[0][0]}") print(f"Probability: {probabilities[0]:.4f}") # Clean up the dummy file os.remove('data.txt')
fasttext --version
Debug
Known issues
breakingThe original `fasttext` Python bindings are incompatible with NumPy 2.0 and newer versions, leading to a `ValueError: Unable to avoid copy while creating an array as requested`. The `fasttext-numpy2` library specifically provides the necessary patches to resolve this issue.
fix
Use `pip install fasttext-numpy2` instead of the original `fasttext` package to ensure compatibility with NumPy 2.x and later.
affects: Original `fasttext` versions (prior to `fasttext-numpy2`'s fix) with NumPy >= 2.0
deprecatedThe original Facebook Research `fastText` GitHub repository (github.com/facebookresearch/fastText) was set to a read-only archive on March 19, 2024, indicating that it is no longer actively maintained by Meta. While the core C++ library remains functional, new features or official patches are unlikely from the original source.
fix
For continued compatibility, especially with evolving Python and NumPy versions, consider using community-maintained forks like `fasttext-numpy2` that address specific compatibility issues.
affects: All versions of the original `fastText` library after March 19, 2024.
gotchaFastText relies heavily on correctly preprocessed and encoded text. It assumes UTF-8 encoding, and inconsistent tokenization or encoding conventions between training and inference can significantly degrade model performance or lead to errors. Ensure all text data is consistently encoded and prepared.
fix
Always ensure your input text files are UTF-8 encoded. Review FastText's documentation on preprocessing data and encoding conventions, especially regarding tokenization and handling of word boundaries.
affects: All versions
gotchaModel binary files (`.bin`) are highly sensitive to the specific library version and compilation settings used to train them. While `fasttext-numpy2` aims for drop-in compatibility, loading a model trained with a significantly different version of fastText (e.g., the original `fastText` vs. `fasttext-numpy2`, or different underlying C++ compiler versions) can lead to unexpected behavior or errors.
fix
Whenever possible, load `.bin` model files with the exact same version of the `fasttext` library (and ideally, the same environment) that was used to train them. If transferring models, verify compatibility with your `fasttext-numpy2` version.
affects: All versions
Errors
Common errors & fixes
ValueError: Unable to avoid copy while creating an array as requested.
The original `fasttext` library is incompatible with NumPy 2.0 due to changes in how `np.array(obj, copy=False)` handles array creation, leading to a `ValueError` when trying to convert data.
fix
Install `fasttext-numpy2`, which is a fork specifically designed to provide compatibility with NumPy 2.x by addressing this underlying NumPy behavior change. `pip install fasttext-numpy2`
ERROR: Could not build wheels for fasttext, which is required to install pyproject.toml-based projects
The `fasttext` library's Python bindings require C++ compilation during installation, and this error indicates that the necessary C++ compiler or build tools are missing or not properly configured on the system, often seen on Windows without Visual C++ Build Tools or Linux without `build-essential`.
fix
Ensure you have the appropriate C++ build tools installed for your operating system (e.g., Visual C++ Build Tools for Windows, `sudo apt-get install build-essential` for Debian/Ubuntu). Alternatively, `fasttext-numpy2` aims to provide pre-built wheels for various platforms, often bypassing the need for local compilation: `pip install fasttext-numpy2`
ModuleNotFoundError: No module named 'fasttext'
This error occurs when the `fasttext-numpy2` library (which is typically imported as `fasttext`) has not been installed correctly, or the Python interpreter cannot find the installed package in its `sys.path`. It can also arise from case sensitivity issues (`fasttext` vs `fastText`) or confusion with other similarly named packages.
fix
First, ensure `fasttext-numpy2` is installed in your active environment using `pip install fasttext-numpy2`. Then, verify the installation with `pip show fasttext-numpy2`. If installed, check that you are running your code with the correct Python interpreter where the package was installed, potentially by activating a virtual environment.
Upgrade
Version history
0.10.4latest on PyPI · released Nov 8, 2024
Audit
Dependencies
numpyrequiredCore dependency for numerical operations; this package specifically fixes compatibility with NumPy 2.x.
setuptoolsrequiredRequired for package installation and build processes.
pybind11requiredUsed for Python-C++ interoperability, as fastText is implemented in C++.
Agent activity
45 hits · last 30 days
node
44
OpenAI (training)
1
Resources
fasttext-numpy2 — pip install fasttext-numpy2 · libregistry