Use the LanguageDetector class
mainThe LanguageDetector class provides high-performance language identification using FastText. It automatically downloads the required model on its first use unless configured otherwise.
Key capabilities:
- Single detection: Detect the primary language and confidence score.
- Top-K predictions: Retrieve multiple possible language candidates.
- Bengali check: Quickly verify if text is Bengali.
- Batch processing: Detect languages for a list of strings efficiently.
- Mixed language detection: Identify proportions of different languages in code-mixed text (e.g., Bengali-English).
from bnlp import LanguageDetector
detector = LanguageDetector()
result = detector.detect("আমি বাংলায় গান গাই")
print(result.language) # 'bn'
print(result.confidence) # ~0.99
print(result.is_bengali) # True