Efficient Language Detector
Efficient language detector (Nito-ELD or ELD) is a fast and accurate language detector, is one of the fastest non compiled detectors, while its accuracy is within the range of the heaviest and slowest detectors.
It's 100% Python, easy installation and no dependencies other than regex
.
ELD is also available in Javascript and PHP.
This is the first version of a port made from the original version in PHP, the structure might not be definitive, the code can be optimized. My knowledge of Python is basic, feel free to suggest improvements.
- Installation
- How to use
- Benchmarks
- Languages
Installation
$ pip install eld
Alternatively, download / clone the files can work too, by changing the import path.
How to use?
from eld import LanguageDetector
detector = LanguageDetector()
detect()
expects a UTF-8 string, and returns an object, with a 'language' variable, which is either an ISO 639-1 code or None
print(detector.detect('Hola, cómo te llamas?'))
print(detector.detect('Hola, cómo te llamas?').language)
detector.clean_text(True)
- To reduce the languages to be detected, there are 3 different options, they only need to be executed once. (Check available languages below)
lang_subset = ['en', 'es', 'fr', 'it', 'nl', 'de']
detector.dynamic_lang_subset(lang_subset)
detector.lang_subset(lang_subset)
detector.lang_subset(None)
langSubsetDetect = LanguageDetector('ngramsL60')
Benchmarks
I compared ELD with a different variety of detectors, since the interesting part is the algorithm.
Benchmarks: Tweets: 760KB, short sentences of 140 chars max.; Big test: 10MB, sentences in all 60 languages supported; Sentences: 8MB, this is the Lingua sentences test, minus unsupported languages.
Short sentences is what ELD and most detectors focus on, as very short text is unreliable, but I included the Lingua Word pairs 1.5MB, and Single words 880KB tests to see how they all compare beyond their reliable limits.
These are the results, first, accuracy and then execution time.
1. Lingua could have a small advantage as it participates with 54 languages, 6 less.
2. CLD2 and CLD3, return a list of languages, the ones not included in this test where discarded, but usually they return one language, I believe they have a disadvantage.
Also, I confirm the results of CLD2 for short text are correct, contrary to the test on the Lingua page, they did not use the parameter "bestEffort = True", their benchmark for CLD2 is unfair.
Lingua is the average accuracy winner, but at what cost, the same test that in ELD or CLD2 is below 10 seconds, in Lingua takes more than 5 hours! It acts like a brute-force software.
Also, its lead comes from single and pair words, which are unreliable regardless.
The Python version of NITO-ELD is not the fastest but is still considered fast, as it is faster than any other non compiled detector tested.
I added ELD-L for comparison, which has a 2.3x bigger database, but only increases execution time marginally, a testament to the efficiency of the algorithm. ELD-L is not the main database as it does not improve language detection in sentences.
Here is the average, per benchmark, of Tweets, Big test & Sentences.

Languages
These are the ISO 639-1 codes of the 60 supported languages for Nito-ELD v1
'am', 'ar', 'az', 'be', 'bg', 'bn', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'eu', 'fa', 'fi', 'fr', 'gu', 'he', 'hi', 'hr', 'hu', 'hy', 'is', 'it', 'ja', 'ka', 'kn', 'ko', 'ku', 'lo', 'lt', 'lv', 'ml', 'mr', 'ms', 'nl', 'no', 'or', 'pa', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sq', 'sr', 'sv', 'ta', 'te', 'th', 'tl', 'tr', 'uk', 'ur', 'vi', 'yo', 'zh'
Full name languages:
Amharic, Arabic, Azerbaijani (Latin), Belarusian, Bulgarian, Bengali, Catalan, Czech, Danish, German, Greek, English, Spanish, Estonian, Basque, Persian, Finnish, French, Gujarati, Hebrew, Hindi, Croatian, Hungarian, Armenian, Icelandic, Italian, Japanese, Georgian, Kannada, Korean, Kurdish (Arabic), Lao, Lithuanian, Latvian, Malayalam, Marathi, Malay (Latin), Dutch, Norwegian, Oriya, Punjabi, Polish, Portuguese, Romanian, Russian, Slovak, Slovene, Albanian, Serbian (Cyrillic), Swedish, Tamil, Telugu, Thai, Tagalog, Turkish, Ukrainian, Urdu, Vietnamese, Yoruba, Chinese
Future improvements
- Train from bigger datasets, and more languages.
- The tokenizer could separate characters from languages that have their own alphabet, potentially improving accuracy and reducing the N-grams database. Retraining and testing is needed.
Donate / Hire
If you wish to Donate for open source improvements, Hire me for private modifications / upgrades, or to Contact me, use the following link: https://linktr.ee/nitotm