DEV Community

Davide Gazzè
Davide Gazzè

Posted on

Language Detection with Fastlangid

In this short post, I will show you an example of the module Spacy fastlangid. This module can detect the language of a text.

The module is based on the model lid.176.ftz based on fastText.

Usage

To use it, import the library and use it. Now, let's see an example:

from fastlangid.langid import LID
langid = LID()
Enter fullscreen mode Exit fullscreen mode

Now, we have the langid object, and we can pass it to the predict:

result = langid.predict('This is a test')
print(f"The detected language is {result}")
Enter fullscreen mode Exit fullscreen mode

The output is:

The detected language is en
Enter fullscreen mode Exit fullscreen mode

For more details see this

Top comments (0)