{"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":"en","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,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}