Green
Green

Reputation: 685

Replicate the command fasttext Query and save FastText vectors

I am setting up nlp preprocessing using pretrained FastText model to query and save word vectors. I ran into FileNotFoundError: [Errno 2] No such file or directory: 'fasttext': 'fasttext' and unable resolve it at this point.

This is for a nlp clinical text similarity project that I am working on. I doubled checked to make sure all the files and folders are present in the directory. I also want to note that I am used both floydhub and google colab to make sure it wasn't a environment issue. I went through the process twice and ended up with the same error. A second set eyes can definitely help.

The code to replicate the command fasttext print-vectors model.bin < words.txt >> vectors.vec is below:

with open(VOCAB_FILE) as f_vocab:
    with open(OUTPUT_FILE, 'a') as f_output:
        subprocess.run(
            [FASTTEXT_EXECUTABLE, 'print-word-vectors', PRETRAINED_MODEL_FILE],
            stdin=f_vocab,
            stdout=f_output)
The traceback error I am getting is below: 

FileNotFoundError                         Traceback (most recent call last)
<ipython-input-150-7b469ee34f75> in <module>()
      4             [FASTTEXT_EXECUTABLE, 'print-word-vectors', PRETRAINED_MODEL_FILE],
      5             stdin=f_vocab,
----> 6             stdout=f_output)

/usr/local/lib/python3.6/subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    401         kwargs['stdin'] = PIPE
    402 
--> 403     with Popen(*popenargs, **kwargs) as process:
    404         try:
    405             stdout, stderr = process.communicate(input, timeout=timeout)

/usr/local/lib/python3.6/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds, encoding, errors)
    707                                 c2pread, c2pwrite,
    708                                 errread, errwrite,
--> 709                                 restore_signals, start_new_session)
    710         except:
    711             # Cleanup if the child failed starting.

/usr/local/lib/python3.6/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1342                         if errno_num == errno.ENOENT:
   1343                             err_msg += ': ' + repr(err_filename)
-> 1344                     raise child_exception_type(errno_num, err_msg, err_filename)
   1345                 raise child_exception_type(err_msg)
   1346 

FileNotFoundError: [Errno 2] No such file or directory: 'fasttext': 'fasttext'

The expected outcome is to be able to query and save fasttext vectors. The code snippet above us obtain from github repo and was used on Kaggles Quora Question Pairs.

Upvotes: 0

Views: 416

Answers (1)

Green
Green

Reputation: 685

Fasttext has to be installed in order to query and save Fasttext vectors.

Upvotes: 0

Related Questions