Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick example of language detection with fasttext small model (less than 1MB model)
# Public Domain CC0 license. https://creativecommons.org/publicdomain/zero/1.0/
# Prepare with: pip install fasttext
# Tested with Python 3.9
import urllib.request
import fasttext
# Download small model (917KB)
# Other options: https://fasttext.cc/docs/en/language-identification.html
urllib.request.urlretrieve('https://dl.fbaipublicfiles.com/fasttext/supervised-models/lid.176.ftz', 'model.ft')
# Predict language of "hello world"
m = fasttext.load_model('model.ft')
m.predict('hello world')
# Returns (('__label__en',), array([0.17635809]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment