Gensim快速文本包装器在模型训练时返回权限错误13

时间:2018-11-04 15:23:49

标签: file-permissions gensim fasttext

我试图在本地计算机上重现this tutorial,以习惯于生成快速文本功能。 Fasttext和gensim库已正确安装。通过调用gensim快速文本包装器的train方法

model_wrapper = FT_wrapper.train(ft_home, lee_train_file)

我收到以下错误:

---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
<ipython-input-19-0815ab031d23> in <module>()
      3 
      4 # train the model
----> 5 model_wrapper = FT_wrapper.train(ft_home, lee_train_file)
      6 
      7 print(model_wrapper)

~/anaconda3/lib/python3.6/site-packages/gensim/models/deprecated/fasttext_wrapper.py in train(cls, ft_path, corpus_file, output_file, model, size, alpha, window, min_count, word_ngrams, loss, sample, negative, iter, min_n, max_n, sorted_vocab, threads)
    240             cmd.append(str(value))
    241 
--> 242         utils.check_output(args=cmd)
    243         model = cls.load_fasttext_format(output_file)
    244         cls.delete_training_files(output_file)

~/anaconda3/lib/python3.6/site-packages/gensim/utils.py in check_output(stdout, *popenargs, **kwargs)
   1795     try:
   1796         logger.debug("COMMAND: %s %s", popenargs, kwargs)
-> 1797         process = subprocess.Popen(stdout=stdout, *popenargs, **kwargs)
   1798         output, unused_err = process.communicate()
   1799         retcode = process.poll()

~/anaconda3/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.

~/anaconda3/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 

PermissionError: [Errno 13] Permission denied: '/Users/marcomattioli/fastText'

请注意,我对fasttext可执行文件具有 -rwxr-xr-x 权限。任何帮助都赞赏如何解决此问题。

1 个答案:

答案 0 :(得分:0)

不推荐使用这些方法。

使用以下代码:

from gensim.models.fasttext import FastText
from gensim.test.utils import datapath
corpus_file = datapath('lee_background.cor')  # absolute path to corpus
model3 = FastText(size=4, window=3, min_count=1)
model3.build_vocab(corpus_file=corpus_file)
total_words = model3.corpus_total_words
model3.train(corpus_file=corpus_file, total_words=total_words, epochs=10)