CNTK icon indicating copy to clipboard operation
CNTK copied to clipboard

EXCEPTION occurred: cannot open word class file

Open hanpum opened this issue 10 years ago • 2 comments

hi, all, while running classbased LM trainning with LSTM, I have found that if define writeWordAndClass section as blow

writeWordAndClassInfo = [
   action = "writeWordAndClass"

   # input train data
   inputFile = "$DataDir$/$trainFile$"

   # four column vocabulary file
   #
   # FORMAT:
   # - the first column is the word id
   # - the second column is the count of the word
   # - the third column is the word 
   # - the fourth column is the class id
   outputVocabFile = "$ModelDir$/vocab.txt"

if outputVocabFile's parent directory(eg, $ModelDir$) doesn't exist, will failed to create vocabulary file, the error message is sth like this: EXCEPTION occurred: cannot open word class file

SOLUTION: just one more line code can fix this problem, modify Source/ActionsLib/OtherActions.cpp, funtion DoWriteWordAndClassInfo(const ConfigParameters& config), around line 431, change from:

    std::ofstream ofvocab;
    ofvocab.open(outputVocabFile.c_str());

to

    std::ofstream ofvocab;
    msra::files::make_intermediate_dirs(s2ws(outputVocabFile));
    ofvocab.open(outputVocabFile.c_str());

recomiple and install cntk, then all'll be well, that's all

hanpum avatar Feb 01 '16 06:02 hanpum

thanks. will update the code.

dongyu888 avatar Feb 01 '16 19:02 dongyu888

this was merged into master

wolfma61 avatar Feb 23 '16 15:02 wolfma61