{"id":5219,"library":"fasttext-predict","title":"fastText Predict","description":"fasttext-predict is a Python package that provides a lightweight, standalone implementation of fastText's prediction functionality. It is specifically designed to include only the `predict` method, making it compact (<1MB) and free of external dependencies, including NumPy. This library aims to provide pre-built wheels for various architectures, ensuring easy installation for deployment scenarios where a full fastText installation is not desired. It is actively maintained with frequent minor updates, offering a stable solution for inference.","status":"active","version":"0.9.2.4","language":"python","source_language":"en","source_url":"https://github.com/searxng/fasttext-predict/","tags":["fasttext","nlp","text-classification","language-detection","embedding","prediction","inference","lightweight"],"install":[{"cmd":"pip install fasttext-predict","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The package name is `fasttext-predict`, but the primary module to import is `fasttext`. Importing directly from `fasttext_predict` is incorrect for typical usage.","wrong":"from fasttext_predict import fasttext","symbol":"fasttext","correct":"import fasttext"}],"quickstart":{"code":"# A fastText model file (e.g., for language identification) needs to be downloaded separately.\n# Example model: lid.176.ftz from https://fasttext.cc/docs/en/language-identification.html\n\nimport fasttext\nimport os\n\n# Ensure the model file is accessible, e.g., placed in the current directory\nmodel_path = os.environ.get('FASTTEXT_MODEL_PATH', 'lid.176.ftz')\n\ntry:\n    model = fasttext.load_model(model_path)\n    text_to_predict = 'Fondant au chocolat et tarte aux myrtilles'\n    predictions = model.predict(text_to_predict)\n    \n    print(f\"Text: '{text_to_predict}'\")\n    print(f\"Predicted label(s): {predictions[0]}\")\n    print(f\"Probabilities: {predictions[1]}\")\n\n    # To get top-k predictions with probabilities\n    top_k_predictions = model.predict(text_to_predict, k=2)\n    print(f\"\\nTop 2 Predicted label(s): {top_k_predictions[0]}\")\n    print(f\"Top 2 Probabilities: {top_k_predictions[1]}\")\n\nexcept ValueError as e:\n    print(f\"Error loading model or making prediction: {e}\")\n    print(\"Please ensure the model file is downloaded and the path is correct.\")\nexcept FileNotFoundError:\n    print(f\"Error: Model file not found at '{model_path}'.\")\n    print(\"Please download 'lid.176.ftz' (or your target model) and place it correctly, or set FASTTEXT_MODEL_PATH environment variable.\")","lang":"python","description":"This quickstart demonstrates how to load a pre-trained fastText model (e.g., for language identification) and use its `predict` method to classify a given text. It also shows how to retrieve multiple top-k predictions and their associated probabilities. A fastText model file must be downloaded and accessible for this example to run correctly."},"warnings":[{"fix":"Use the original `fasttext` library (e.g., `pip install fasttext`) for training or other advanced features. This `fasttext-predict` library is specifically for lightweight inference.","message":"This library provides *only* the prediction functionality (`predict` method) of fastText. Training, model quantization, word/sentence vector generation, or other utilities available in the full `fasttext` library are explicitly *not* included. Attempting to call non-prediction methods will result in an `AttributeError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `import fasttext` after installing `fasttext-predict`.","message":"The Python package name for installation is `fasttext-predict`, but the correct Python import statement is `import fasttext`. Users accustomed to other `pip install X` -> `import X` patterns should be aware of this difference to avoid `ModuleNotFoundError`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Monitor actively maintained forks of the original `fastText` library for training new models if long-term support for model generation is critical. Ensure model versions are compatible with `fasttext-predict`.","message":"Models used with `fasttext-predict` are typically trained with the original `fastText` library (facebookresearch/fastText), which was set to a read-only archive on March 19, 2024. While `fasttext-predict` is actively maintained for prediction, users should be aware of the upstream project's archived status and consider potential long-term implications for model format compatibility or training new models with actively developed forks of `fastText`.","severity":"breaking","affected_versions":"Models trained with fastText versions potentially impacted by upstream archive status."},{"fix":"Preprocess input text to remove or replace newline characters (e.g., `text.replace('\\n', ' ')`) and ensure each element passed for prediction is a properly formatted string.","message":"The `predict` method expects clean, single-line text input. Newline characters (`\\n`) or other special formatting within input strings can lead to incorrect predictions or errors, especially when processing text from sources like dataframes. Each prediction input should ideally be a single, pre-processed string.","severity":"gotcha","affected_versions":"All versions"},{"fix":"To get top-k predictions, call `model.predict(text, k=N)` where `N` is the desired number of predictions.","message":"By default, `model.predict()` returns only the single top predicted label and its corresponding probability. To retrieve multiple labels (e.g., the top-k most likely labels) and their probabilities for a given text, the `k` parameter must be explicitly passed to the `predict` method.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1mb':34 'activ':70 'aim':44 'architectur':53 'built':49 'classif':86 'compact':33 'depend':39 'deploy':58 'design':24 'desir':67 'detect':89 'easi':55 'embed':90 'ensur':54 'extern':38 'fasttext':1,4,17,63,82 'fasttext-predict':3 'free':36 'frequent':73 'full':62 'function':20 'implement':15 'includ':26,40 'infer':81,92 'instal':56,64 'languag':88 'language-detect':87 'librari':43 'lightweight':13,93 'maintain':71 'make':31 'method':30 'minor':74 'nlp':83 'numpi':41 'offer':76 'packag':9 'pre':48 'pre-built':47 'predict':2,5,19,29,91 'provid':11,46 'python':8 'scenario':59 'solut':79 'specif':23 'stabl':78 'standalon':14 'text':85 'text-classif':84 'updat':75 'various':52 'wheel':50","created_at":"2026-04-14T01:24:21.552111+00:00","updated_at":"2026-04-16T14:59:11.649984+00:00","problems":[{"fix":"Ensure the package is installed using `pip install fasttext-predict` in your active Python environment.","cause":"The `fasttext-predict` package is not installed or the Python environment where it's installed is not active.","error":"ModuleNotFoundError: No module named 'fasttext_predict'"},{"fix":"Use the full `fasttext` library (`pip install fasttext`) if you need training capabilities. If you only need prediction, ensure you are calling the `predict` method on the loaded model and not attempting to train or use other methods.","cause":"The `fasttext-predict` library is a lightweight version of fastText that only includes the prediction functionality. It does not support model training or other utility methods like `train_supervised`.","error":"AttributeError: 'Model' object has no attribute 'train_supervised'"},{"fix":"If you require access to word vectors or other model components, you need to install and use the complete `fasttext` library (`pip install fasttext`).","cause":"The `fasttext-predict` library is specifically designed for prediction only and does not include methods for retrieving word vectors (`get_word_vector`), sentence vectors, or other model introspection capabilities of the full `fasttext` library.","error":"AttributeError: 'Model' object has no attribute 'get_word_vector'"},{"fix":"Preprocess your input strings to remove unwanted characters like newlines before passing them to the `predict` method. For example: `cleaned_text = text.replace('\\n', ' ').strip()`.","cause":"The `predict` method in fastText (and by extension `fasttext-predict`) expects clean text inputs, typically without newline characters or other extraneous formatting that might interfere with tokenization or prediction, especially when processing text line by line from a file-like input or iterable. While `fasttext-predict`'s `predict` can accept a list of strings, individual strings in the list should be preprocessed.","error":"fasttext-predict error: predict processes one line at a time (remove '\\n')"},{"fix":"Import `load_model` directly from the `fasttext_predict` package: `from fasttext_predict import load_model`, then use `model = load_model('path/to/model.bin')`.","cause":"Users attempting to use `fasttext_predict.fasttext.load_model` (or similar) when the `fasttext-predict` library directly exposes `load_model` at the top level, or confusing the import structure with the full `fasttext` library.","error":"AttributeError: module 'fasttext_predict' has no attribute 'fasttext'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.9.2.4","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/searxng/fasttext-predict","docs":null,"changelog":null,"pypi":"https://pypi.org/project/fasttext-predict/","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-08-30","next_check":"2026-07-28","install_tag":null}}