You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importreimportfasttexttry:
fromimportlib.resourcesimportfilesexceptImportError: # python < 3.10. https://setuptools.pypa.io/en/latest/userguide/datafiles.htmlfromimportlib_resourcesimportfilesfasttext_model_path=str(files('ivory_data_forge.data').joinpath("lid.176.ftz")) # this works only for python >=3.10print(fasttext_model_path)
model=fasttext.load_model(fasttext_model_path)
defdetect_language(s):
"""Detect whether a string is in English, Dutch or another language. When used on short strings (such as job titles), the confidence can be quite low (0.2) even though reading the string makes clear that the prediction is correct. Args: s (str): Text to infer language from. """predictions=model.predict(s)
language=re.sub("__label__", "", predictions[0][0])
# confidence = predictions[1][0] iflanguagein ["nl", "en"]:
returnlanguagereturn"other"
The text was updated successfully, but these errors were encountered:
https://fasttext.cc/
Following example from Flavio:
The text was updated successfully, but these errors were encountered: