Background
I would like to execute the code to categorize language of each text using fastText.
What I have done
downloaded the model
lid.176.bin
https://fasttext.cc/docs/en/language-identification.htmlinstalled the python binding
$ git clone https://github.com/facebookresearch/fastText.git
$ cd fastText
$ pip install .
The above the model lid.176.bin
and the folder fastText
are located on the same level as the below python code exists.
I have no idea how to avoid the error.
Error
ImportError: No module named fastText
Code
sample.py
from fastText import load_model
model = load_model("lid.176.bin")
speech_texts = ["Hello, guys. What's up?", '你好! 我是学生。', 'Hallo, ich habe das Buch.']
def categorize(texts):
for i in range(len(texts)):
text = texts[i]
label, prob = model.predict(text, k)
return list(zip([l.replace("__label__", "") for l in label], prob))
categorize(speech_texts)
Response to the answer
- I have tried to execute the command following the answer, but still I am struggling to fix the same error.
$ pip3 install fasttext
Requirement already satisfied: fasttext in /usr/local/lib/python3.9/site-packages (0.9.2)
Requirement already satisfied: setuptools>=0.7.0 in /usr/local/lib/python3.9/site-packages (from fasttext) (51.1.1)
Requirement already satisfied: numpy in /usr/local/lib/python3.9/site-packages (from fasttext) (1.19.5)
Requirement already satisfied: pybind11>=2.2 in /usr/local/lib/python3.9/site-packages (from fasttext) (2.6.1)
from fasttext import load_model
ImportError: No module named fasttext
- packages that I have installed
$ pip3 freeze
fasttext @ file:///Users/username/Desktop/sample/fastText
numpy==1.19.5
pybind11==2.6.1
Develop Environment
Python 3.9
Mac OS Big Sur