{"id":3489,"library":"fasttext","title":"fastText Python Bindings","description":"fastText is a library for efficient learning of word representations and sentence classification. Developed by Facebook AI Research, it's particularly good for large-scale text processing tasks. The current version is 0.9.3, with releases focusing on new features, performance, and API stability rather than a fixed cadence.","status":"active","version":"0.9.3","language":"python","source_language":"en","source_url":"https://github.com/facebookresearch/fastText","tags":["nlp","text-classification","word-embeddings","machine-learning","facebook-ai"],"install":[{"cmd":"pip install fasttext","lang":"bash","label":"Install fasttext"}],"dependencies":[],"imports":[{"note":"Prior to v0.9.1, the official GitHub module was 'fastText', while PyPI had an unofficial 'fasttext'. They merged, and the official import is now 'fasttext'.","wrong":"import fastText","symbol":"fasttext","correct":"import fasttext"}],"quickstart":{"code":"import fasttext\nimport os\n\n# Create a dummy training file for demonstration\ntraining_data_path = 'train.txt'\nwith open(training_data_path, 'w') as f:\n    f.write('__label__positive This is a good movie.\\n')\n    f.write('__label__negative This movie was terrible.\\n')\n    f.write('__label__positive I love this film.\\n')\n\n# Train a supervised model\nmodel = fasttext.train_supervised(input=training_data_path)\n\n# Predict a label\ntext_to_predict = 'This is an excellent film.'\npredictions = model.predict(text_to_predict)\nprint(f\"Text: '{text_to_predict}'\")\nprint(f\"Prediction: {predictions[0][0]}, Probability: {predictions[1][0]:.4f}\")\n\n# Clean up dummy file\nos.remove(training_data_path)\n","lang":"python","description":"This quickstart demonstrates how to train a basic supervised text classification model and make predictions using fastText. The training data must be in the specific fastText format with `__label__` prefixes."},"warnings":[{"fix":"Ensure you are importing `fasttext` (lowercase) and refer to the v0.9.1+ documentation for updated API calls, particularly `fasttext.load_model()` and training parameters. Uninstall any old `fastText` installations before reinstalling `fasttext`.","message":"Version 0.9.1 merged the previously separate official 'fastText' (from GitHub) and unofficial 'fasttext' (from PyPI) Python modules. This involved significant API changes, especially for users who were previously installing directly from GitHub.","severity":"breaking","affected_versions":"<0.9.1"},{"fix":"Ensure you have a C++ compiler (e.g., GCC, Clang for Linux/macOS, MSVC for Windows) installed and correctly configured in your PATH. On Windows, this often means installing 'Build Tools for Visual Studio'.","message":"Installation on some operating systems (e.g., Windows, or macOS without specific tools) can fail due to C++ compilation requirements. fastText is a C++ library with Python bindings.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always save your trained fastText models using `model.save_model('model.bin')` and load them with `fasttext.load_model('model.bin')`. If you only have `.vec` files, you'll need to retrain or find the original `.bin` model.","message":"The `fasttext.load_model()` function expects a `.bin` model file, which contains both word vectors and classification information. It cannot directly load standalone `.vec` (vector) files.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pre-process your training data to match the fastText input format. Each line is a document, and each document starts with its label(s) prefixed by `__label__`.","message":"Training data for supervised classification (e.g., `train_supervised`) must adhere to a specific format: each line should contain the label prefixed with `__label__`, followed by the text, for example: `__label__positive This is a great product.`","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.9.3':37 'ai':20,65 'api':46 'bind':3 'cadenc':52 'classif':16,56 'current':34 'develop':17 'effici':9 'embed':59 'facebook':19,64 'facebook-ai':63 'fasttext':1,4 'featur':43 'fix':51 'focus':40 'good':25 'larg':28 'large-scal':27 'learn':10,62 'librari':7 'machin':61 'machine-learn':60 'new':42 'nlp':53 'particular':24 'perform':44 'process':31 'python':2 'rather':48 'releas':39 'represent':13 'research':21 'scale':29 'sentenc':15 'stabil':47 'task':32 'text':30,55 'text-classif':54 'version':35 'word':12,58 'word-embed':57","created_at":"2026-04-11T17:31:48.627551+00:00","updated_at":"2026-04-16T14:58:55.544891+00:00","problems":[{"fix":"Ensure fastText is installed using `pip install fasttext`. If you have a local file named `fasttext.py`, rename it to avoid conflicts. If using Anaconda, try `conda install -c conda-forge fasttext`.","cause":"This error typically occurs when the `fasttext` Python package is not installed correctly in the active Python environment, or a local file named `fasttext.py` is shadowing the installed library.","error":"ModuleNotFoundError: No module named 'fasttext'"},{"fix":"Ensure you are using the correct FastText API. For the official fastText Python binding, methods like `load_model` are directly available after `import fasttext`. If you are using Gensim's implementation, you would typically import `from gensim.models import FastText` and the model object would have methods like `wv.most_similar()`. Also, check for any local file named `fasttext.py` that might be overriding the package import. A correct usage example would be `import fasttext; model = fasttext.load_model('model.bin')`.","cause":"This usually happens when attempting to call a method like `load_model` (or `train_supervised`, `predict`, etc.) directly on the `fasttext` module, but the method is either not directly exposed this way in your installed version or a local `fasttext.py` file is preventing the correct module from being loaded. It can also occur if there's confusion between the official `fasttext` library and Gensim's `FastText` wrapper.","error":"AttributeError: module 'fasttext' has no attribute 'load_model'"},{"fix":"Download the latest pre-trained models from the official fastText website (www.fasttext.cc) or ensure that your custom-trained model was saved correctly and is not corrupted. If you trained the model yourself, verify the training and saving process.","cause":"This error indicates that the model file you are trying to load is either corrupted, an older version that is incompatible with your current `fasttext` library, or not a valid fastText model file (.bin or .ftz format).","error":"ValueError: Invalid model file. Please download the updated model from www.fasttext.cc."},{"fix":"Downgrade your NumPy version to a compatible one (e.g., `pip install numpy<2`) or try installing a `fasttext` wheel specifically built for newer NumPy versions if available. If building from source, ensure you have a compatible compiler and NumPy version when compiling fastText. Some users have found success with alternative `fasttext` wheels for Windows that address NumPy compatibility.","cause":"This error typically arises due to an incompatibility between the installed `fasttext` library (which has C++ extensions) and a recently updated NumPy version, especially with the release of NumPy 2.0. The binary extensions of `fasttext` were compiled against an older NumPy API.","error":"ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected X from C header, got Y from PyObject."},{"fix":"Verify that the input file path passed to the training function is correct and that the file exists at that location. Ensure that the Python process has the necessary read permissions for the file. For example, `model = fasttext.train_supervised(input='path/to/your/data.txt')`.","cause":"This error occurs when the `fasttext.train_supervised()` or `fasttext.train_unsupervised()` function cannot locate or access the specified input training file. This is often due to an incorrect file path, the file not existing, or insufficient permissions.","error":"ValueError: <filename> cannot be opened for training!"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.9.3","cli_name":"fasttext","cli_version":"","type":"library","homepage":null,"github":"https://github.com/facebookresearch/fastText","docs":null,"changelog":null,"pypi":"https://pypi.org/project/fasttext/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","data","llm-agents"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"failing","verified_at":"2026-06-28","last_verified":"2026-08-29","next_check":"2026-07-28","install_tag":null}}