{"id":2024,"library":"fasttext-wheel","title":"FastText Python Bindings","description":"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.","status":"active","version":"0.9.2","language":"python","source_language":"en","source_url":"https://github.com/facebookresearch/fastText","tags":["NLP","text classification","word embeddings","natural language processing","machine learning"],"install":[{"cmd":"pip install fasttext-wheel","lang":"bash","label":"Install via pip"}],"dependencies":[],"imports":[{"note":"Prior to v0.9.1, the official GitHub module used 'from fastText import fastText'. The current consolidated module is 'fasttext'.","wrong":"from fastText import fastText","symbol":"fasttext","correct":"import fasttext"}],"quickstart":{"code":"import fasttext\nimport os\n\n# Create a dummy training data file (replace with your actual data)\n# Format: __label__label1 text1\n#         __label__label2 text2\ntrain_file = \"train.txt\"\nwith open(train_file, \"w\") as f:\n    f.write(\"__label__positive this movie is great\\n\")\n    f.write(\"__label__negative this movie is terrible\\n\")\n    f.write(\"__label__positive i love this film\\n\")\n    f.write(\"__label__negative what a waste of time\\n\")\n\n# Train a supervised text classification model\n# Adjust parameters like epoch, lr, wordNgrams for your specific task\nmodel = fasttext.train_supervised(input=train_file, epoch=25, lr=1.0, wordNgrams=2)\n\n# Predict labels for new text\nprint(\"Prediction for 'this movie is wonderful':\", model.predict(\"this movie is wonderful\"))\nprint(\"Prediction for 'worst movie ever':\", model.predict(\"worst movie ever\"))\n\n# Optionally save and load the model\nmodel_path = \"model.bin\"\nmodel.save_model(model_path)\nloaded_model = fasttext.load_model(model_path)\nprint(\"Loaded model prediction:\", loaded_model.predict(\"this film is amazing\"))\n\n# Clean up dummy file\nos.remove(train_file)\nos.remove(model_path)","lang":"python","description":"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."},"warnings":[{"fix":"Update your import statements from `from fastText import fastText` or similar to `import fasttext`.","message":"The 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`.","severity":"breaking","affected_versions":">=0.9.1"},{"fix":"Ensure your training data file adheres to the `__label__` format for each line. E.g., `__label__pos This is a positive review.`","message":"Supervised learning (`train_supervised`) requires input data to be formatted with `__label__` prefixes. Each line must contain `__label__<label_name> <text_content>`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Access the predicted label using `result[0][0][0]` and probability using `result[1][0][0]` for single-label, single-input predictions.","message":"The `model.predict()` method returns a tuple containing two lists: `([['label']], [array([probability])])`. Users often incorrectly expect a single string or float.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Monitor memory usage; consider reducing `wordNgrams` or `dim`, or use `quantize_model()` for smaller memory footprint models post-training.","message":"FastText 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always refer to the latest official Python documentation for current API methods. If using older versions, be aware of potential method deprecation/removal.","message":"The 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.","severity":"deprecated","affected_versions":"0.2.0-0.9.0"}],"env_vars":null,"search_vec":"'0.9.2':49 'access':63 'activ':56 'ai':15 'bind':3,36 'broader':62 'c':41 'classif':25,66 'compil':34 'core':39,59 'current':46 'develop':12 'effici':18 'embed':22,68 'facebook':14 'fasttext':1,4,28,40 'fasttext-wheel':27 'focus':57 'improv':60 'infrequ':54 'instal':44 'languag':70 'learn':19,73 'librari':11,42 'lightweight':10 'machin':72 'natur':69 'nlp':64 'open':8 'open-sourc':7 'packag':30 'pre':33 'pre-compil':32 'process':71 'provid':31 'python':2,35 'releas':51 'research':16 'somewhat':53 'sourc':9 'streamlin':43 'text':24,65 'version':47 'wheel':29 'word':21,67","created_at":"2026-04-09T18:40:15.928646+00:00","updated_at":"2026-04-16T14:59:11.957074+00:00","problems":[{"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).","cause":"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.","error":"ERROR: Failed building wheel for fasttext"},{"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.","cause":"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.","error":"ModuleNotFoundError: No module named 'fasttext'"},{"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.","cause":"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`.","error":"AttributeError: module 'fasttext' has no attribute 'train_supervised'"},{"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.","cause":"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.","error":"UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.9.2","cli_name":"fasttext","cli_version":"sh: 1: fasttext: not found","type":"library","homepage":null,"github":"https://github.com/facebookresearch/fastText","docs":null,"changelog":null,"pypi":"https://pypi.org/project/fasttext-wheel/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}