r/learnpython • • 6d ago

Variability in langdetect output

Hi all,
I’m using Python to filter out rows that contains non-English text from a noisy 10,000-row Excel dataset, and the final count varies slightly between runs (for example, keeping 7,522 vs. 7,508 cells—a difference of less than 0.001% of total cells). Is that normal for noisy data, and is that level of variance acceptable for research?

Thanks all!

3 Upvotes

8 comments sorted by

View all comments

2

u/lakseol 6d ago

The langdetect page in PyPi has this:

Language detection algorithm is non-deterministic, which means that if you
try to run it on a text which is either too short or too ambiguous, you might
get different results everytime you run it.

To enforce consistent results, call following code before the first language
detection:

    from langdetect import DetectorFactory
    DetectorFactory.seed = 0

You will have to experiment a bit to see if this helps in your case.