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