Last active
May 17, 2021 20:45
-
-
Save dlebech/3c9fc5b74c4b080622188d409aaef05d to your computer and use it in GitHub Desktop.
Quick example of language detection with fasttext small model (less than 1MB model)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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