epfml / sent2vec

General purpose unsupervised sentence representations
Other
1.19k stars 256 forks source link

call is not working even with fasttext provided by this repository #15

Closed vsbiradar closed 6 years ago

vsbiradar commented 6 years ago

the call is giving ouput as 2, so its not running properly. when I checked the output of call using check_output method in subprocess it says the command returned non-zero exit. I am attaching the trace of the error.

CalledProcessError Traceback (most recent call last)

in () 1 sentences = ['Once upon a time.', 'And now for something completely different.'] 2 ----> 3 my_embeddings = get_sentence_embeddings(sentences, 'unigrams', 'wiki') 4 print(my_embeddings.shape) in get_sentence_embeddings(sentences, ngram, model) 67 68 if ngram == 'unigrams': ---> 69 wiki_embeddings = get_embeddings_for_preprocessed_sentences(tokenized_sentences_SNLP, MODEL_WIKI_UNIGRAMS, FASTTEXT_EXEC_PATH) 70 print "came to if" 71 else: in get_embeddings_for_preprocessed_sentences(sentences, model_path, fasttext_exec_path) 13 model_path + ' < '+ 14 test_path + ' > ' + ---> 15 embeddings_path, shell=True) 16 embeddings = read_embeddings(embeddings_path) 17 os.remove(test_path) /home/vaijenath/anaconda2/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs) 571 if cmd is None: 572 cmd = popenargs[0] --> 573 raise CalledProcessError(retcode, cmd, output=output) 574 return output 575 CalledProcessError: Command '/home/vaijenath/Vaiju/Project/all code and data/My Code/sent2vec-master/src/fasttext print-sentence-vectors /home/vaijenath/Vaiju/Project/all code and data/My Code/TrainedModels/wiki_unigrams.bin < /home/vaijenath/Vaiju/Project/all code and data/My Code/sent2vec-master/1511975965.08_fasttext.test.txt > /home/vaijenath/Vaiju/Project/all code and data/My Code/sent2vec-master/1511975965.08_fasttext.embeddings.txt' returned non-zero exit status 2 where, /home/vaijenath/Vaiju/Project/all code and data/My Code/sent2vec-master/ is my path where i am running this file.
martinjaggi commented 6 years ago

please can you first check if you get a similar issue if you try the same dataset with fasttext instead of sent2vec? this would be important to know since your issue is about a code part with is mostly shared with fasttext.

vsbiradar commented 6 years ago

Yes. I tried that. And it is working fine. When i run sent2vec using facebook's fasttext it is running from terminal but giving error OSError: [Errno 2] No such file or directory while it running from python notebook. If I use fasttext.cc given in this git repository i am getting above error.

vsbiradar commented 6 years ago

from subprocess import check_output from subprocess import call a = call('./fasttext print-sentence-vectors ~/Vaiju/Project/all code and data/My Code/TrainedModels/wiki_unigrams.bin < 1fasttext.test.txt')

The error is

OSError Traceback (most recent call last)

in () 1 from subprocess import check_output 2 from subprocess import call ----> 3 a = call('./fasttext print-sentence-vectors ~/Vaiju/Project/all code and data/My Code/TrainedModels/wiki_unigrams.bin < 1fasttext.test.txt') 4 5 /home/vaijenath/anaconda2/lib/python2.7/subprocess.pyc in call(*popenargs, **kwargs) 520 retcode = call(["ls", "-l"]) 521 """ --> 522 return Popen(*popenargs, **kwargs).wait() 523 524 /home/vaijenath/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags) 708 p2cread, p2cwrite, 709 c2pread, c2pwrite, --> 710 errread, errwrite) 711 except Exception: 712 # Preserve original exception in case os.close raises. /home/vaijenath/anaconda2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) 1333 raise 1334 child_exception = pickle.loads(data) -> 1335 raise child_exception 1336 1337 OSError: [Errno 2] No such file or directory But this works fine from terminal.
martinjaggi commented 6 years ago

so if it runs fine from terminal why does your python not call the same function? you never actually shared your python code so it's hard for me to see what you are trying

vsbiradar commented 6 years ago

from subprocess import check_output from subprocess import call a1 = check_output('./fasttext supervised -input traindata.ft.txt -output model_kaggle -label label',shell=True)

a = check_output('./fasttext print-sentence-vectors ~/Vaiju/Project/all code and data/My Code/TrainedModels/wiki_unigrams.bin < 1fasttext.test.txt', shell=True)

The first one works fine but second call gives error The error trace is: CalledProcessError Traceback (most recent call last) in () 3 print check_output('./fasttext supervised -input traindata.ft.txt -output model_kaggle -label label',shell=True) 4 ----> 5 a = check_output('./fasttext print-sentence-vectors ~/Vaiju/Project/all code and data/My Code/TrainedModels/wiki_unigrams.bin < 1fasttext.test.txt', shell=True) 6 7

/home/vaijenath/anaconda2/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs) 571 if cmd is None: 572 cmd = popenargs[0] --> 573 raise CalledProcessError(retcode, cmd, output=output) 574 return output 575

CalledProcessError: Command './fasttext print-sentence-vectors ~/Vaiju/Project/all code and data/My Code/TrainedModels/wiki_unigrams.bin < 1fasttext.test.txt' returned non-zero exit status 1

where 1fasttexttest.txt is a file containing sentences.

mpagli commented 6 years ago

Hi vsbiradar,

That's just a wild guess, but could you try removing spaces from you paths ?

/home/vaijenath/Vaiju/Project/all code and data/My Code/sent2vec-master/ would become /home/vaijenath/Vaiju/Project/all_code_and_data/My_Code/sent2vec-master/