fasttext-langdetect is a Python wrapper for Facebook's FastText language identification model. It offers fast and up to 95% accurate language detection across over 170 languages. The library, currently at version 1.0.5 (last released in January 2023), provides a straightforward interface for identifying the language of a given text string. It downloads the necessary FastText model on its first use.
pip install fasttext-langdetectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import the `detect` function and use it to identify the language of a given text. It shows examples for both the full accuracy model (default) and the low-memory model.
Ensure network connectivity and appropriate disk space for the initial model download. The model typically caches in a temporary system directory.
Choose `low_memory=True` for memory-constrained environments at the cost of slight accuracy, or `low_memory=False` (default) for maximum accuracy.
For short texts, results may be less reliable. Consider providing more context if possible. For very long texts, breaking them into smaller, meaningful segments might improve accuracy.
Consider pre-processing input text (e.g., lowercasing, basic cleaning) if dealing with informal or noisy user-generated content to potentially improve results.
Ensure the package is installed using `pip install fasttext-langdetect` and use the correct import: `from ftlangdetect import detect`.
Ensure a stable internet connection during the first use for automatic model download, or if using a custom model, verify its integrity and the correctness of the file path. Clearing the library's cache directory (usually in a system temp location or specified by FTLANG_CACHE) can resolve issues with corrupted auto-downloaded models.
When calling `detect()`, explicitly use the `model='lite'` option to load a smaller, less memory-intensive model (e.g., `detect(text='...', model='lite')`). Alternatively, use `model='auto'`, which attempts to fall back to the lite model if loading the full model causes a MemoryError. Ensure your system has adequate RAM if you require the 'full' model.
Import the `detect` function directly using `from ftlangdetect import detect` and then call it as `detect(text='your text here')`.
No dependency data recorded yet.