diff --git a/src/lm/arpa-file-parser-test.cc b/src/lm/arpa-file-parser-test.cc index 5b5421873c4..00a76418098 100644 --- a/src/lm/arpa-file-parser-test.cc +++ b/src/lm/arpa-file-parser-test.cc @@ -149,7 +149,7 @@ void TestableArpaFileParser::Validate( // expect_ngrams.array, CompareNgrams); // if (mpos.first != ngrams_.end()) // KALDI_ERR << "Maismatch at index " << mpos.first - ngrams_.begin(); - //TODO:auto above requres C++11, and I cannot spell out the type!!! + // TODO: auto above requres C++11, and I cannot spell out the type!!! KALDI_ASSERT(std::equal(ngrams_.begin(), ngrams_.end(), expect_ngrams.array, CompareNgrams)); } diff --git a/src/lm/arpa-file-parser.h b/src/lm/arpa-file-parser.h index fc7c83deb30..8c4ada5692d 100644 --- a/src/lm/arpa-file-parser.h +++ b/src/lm/arpa-file-parser.h @@ -21,11 +21,11 @@ #ifndef KALDI_LM_ARPA_FILE_PARSER_H_ #define KALDI_LM_ARPA_FILE_PARSER_H_ +#include + #include #include -#include - #include "base/kaldi-types.h" #include "itf/options-itf.h" @@ -38,7 +38,7 @@ struct ArpaParseOptions { enum OovHandling { kRaiseError, ///< Abort on OOV words kAddToSymbols, ///< Add novel words to the symbol table. - kReplaceWithUnk, ///< Replace OOV words with . + kReplaceWithUnk, ///< Replace OOV words with . kSkipNGram ///< Skip n-gram with OOV word and continue. }; @@ -59,7 +59,7 @@ struct ArpaParseOptions { int32 eos_symbol; ///< Symbol for , Required non-epsilon. int32 unk_symbol; ///< Symbol for , Required for kReplaceWithUnk. OovHandling oov_handling; ///< How to handle OOV words in the file. - int32 max_warnings; ///< Maximum warnings to report, <0 unlimited. + int32 max_warnings; ///< Maximum warnings to report, <0 unlimited. }; /** diff --git a/src/lm/arpa-lm-compiler-test.cc b/src/lm/arpa-lm-compiler-test.cc index 8242b6fc266..8d2e953304e 100644 --- a/src/lm/arpa-lm-compiler-test.cc +++ b/src/lm/arpa-lm-compiler-test.cc @@ -33,7 +33,7 @@ namespace kaldi { enum { kEps = 0, kDisambig, - kBos,kEos, + kBos, kEos, }; // Number of random sentences for coverage test. @@ -227,8 +227,7 @@ int main(int argc, char *argv[]) { if (ok) { KALDI_LOG << "All tests passed"; return 0; - } - else { + } else { KALDI_WARN << "Test FAILED"; return 1; } diff --git a/src/lm/const-arpa-lm.cc b/src/lm/const-arpa-lm.cc index bb1517c8875..8c848d245a9 100644 --- a/src/lm/const-arpa-lm.cc +++ b/src/lm/const-arpa-lm.cc @@ -176,7 +176,7 @@ class LmState { // auxiliary class LmState above. class ConstArpaLmBuilder : public ArpaFileParser { public: - ConstArpaLmBuilder(ArpaParseOptions options) + explicit ConstArpaLmBuilder(ArpaParseOptions options) : ArpaFileParser(options, NULL) { ngram_order_ = 0; num_words_ = 0; diff --git a/src/lm/mikolov-rnnlm-lib.cc b/src/lm/mikolov-rnnlm-lib.cc index d1afd666539..b1abb29dee7 100644 --- a/src/lm/mikolov-rnnlm-lib.cc +++ b/src/lm/mikolov-rnnlm-lib.cc @@ -66,7 +66,7 @@ static union { int j, i; } n; } d2i; -#define EXP_A (1048576/M_LN2) +#define EXP_A (1048576 / M_LN2) #define EXP_C 60801 #define FAST_EXP(y) (d2i.n.i = EXP_A * (y) + (1072693248 - EXP_C), d2i.d) @@ -147,7 +147,7 @@ CRnnLM::CRnnLM() { srand(rand_seed); vocab_hash_size = 100000000; - vocab_hash = (int *)calloc(vocab_hash_size, sizeof(int)); + vocab_hash = reinterpret_cast(calloc(vocab_hash_size, sizeof(int))); } CRnnLM::~CRnnLM() { @@ -178,7 +178,9 @@ CRnnLM::~CRnnLM() { free(syn1b); if (syncb != NULL) free(syncb); - for (i = 0; i < class_size; i++) free(class_words[i]); + for (i = 0; i < class_size; i++) { + free(class_words[i]); + } free(class_max_cn); free(class_cn); free(class_words); @@ -195,7 +197,7 @@ CRnnLM::~CRnnLM() { } real CRnnLM::random(real min, real max) { - return rand()/(real)RAND_MAX*(max-min)+min; + return rand() / (real)RAND_MAX * (max - min) + min; } void CRnnLM::setRnnLMFile(const std::string &str) { @@ -222,7 +224,7 @@ void CRnnLM::readWord(char *word, FILE *fin) { } if (ch == '\n') { - strcpy(word, (char *)""); + strcpy(word, const_cast("")); return; } else { continue; @@ -244,7 +246,9 @@ int CRnnLM::getWordHash(const char *word) { unsigned int hash, a; hash = 0; - for (a = 0; a < strlen(word); a++) hash = hash * 237 + word[a]; + for (a = 0; a < strlen(word); a++) { + hash = hash * 237 + word[a]; + } hash = hash % vocab_hash_size; return hash; @@ -275,8 +279,9 @@ void CRnnLM::sortVocab() { for (a = 1; a < vocab_size; a++) { max = a; - for (b = a + 1; b < vocab_size; b++) + for (b = a + 1; b < vocab_size; b++) { if (vocab[max].cn < vocab[b].cn) max = b; + } swap = vocab[max]; vocab[max] = vocab[a]; @@ -307,24 +312,30 @@ void CRnnLM::saveWeights() { // saves current weights and unit activations neu2b[a].er = neu2[a].er; } - for (b = 0; b < layer1_size; b++) + for (b = 0; b < layer1_size; b++) { for (a = 0; a < layer0_size; a++) { syn0b[a + b * layer0_size].weight = syn0[a + b * layer0_size].weight; } + } if (layerc_size > 0) { - for (b = 0; b < layerc_size; b++) for (a = 0; a < layer1_size; a++) { - syn1b[a + b * layer1_size].weight = syn1[a + b * layer1_size].weight; + for (b = 0; b < layerc_size; b++) { + for (a = 0; a < layer1_size; a++) { + syn1b[a + b * layer1_size].weight = syn1[a + b * layer1_size].weight; + } } - for (b = 0; b < layer2_size; b++) for (a = 0; a < layerc_size; a++) { - syncb[a + b * layerc_size].weight = sync[a + b * layerc_size].weight; + for (b = 0; b < layer2_size; b++) { + for (a = 0; a < layerc_size; a++) { + syncb[a + b * layerc_size].weight = sync[a + b * layerc_size].weight; + } } } else { - for (b = 0; b < layer2_size; b++) + for (b = 0; b < layer2_size; b++) { for (a = 0; a < layer1_size; a++) { syn1b[a + b * layer1_size].weight = syn1[a + b * layer1_size].weight; } + } } // for (a = 0; a < direct_size; a++) syn_db[a].weight = syn_d[a].weight; @@ -364,12 +375,14 @@ void CRnnLM::initNet() { exit(1); } - syn_d = (direct_t *)calloc((long long)direct_size, sizeof(direct_t)); + syn_d = + reinterpret_cast(calloc(static_cast(direct_size), + sizeof(direct_t))); if (syn_d == NULL) { printf("Memory allocation for direct" - " connections failed (requested %lld bytes)\n", - (long long)direct_size * (long long)sizeof(direct_t)); + " connections failed (requested %ld bytes)\n", + static_cast(direct_size) * static_cast(sizeof(direct_t))); exit(1); } @@ -418,40 +431,49 @@ void CRnnLM::initNet() { neu2[a].er = 0; } - for (b = 0; b < layer1_size; b++) + for (b = 0; b < layer1_size; b++) { for (a = 0; a < layer0_size; a++) { syn0[a + b * layer0_size].weight = random(-0.1, 0.1) + random(-0.1, 0.1) + random(-0.1, 0.1); } + } if (layerc_size > 0) { - for (b = 0; b < layerc_size; b++) + for (b = 0; b < layerc_size; b++) { for (a = 0; a < layer1_size; a++) { syn1[a + b * layer1_size].weight = random(-0.1, 0.1) + random(-0.1, 0.1) + random(-0.1, 0.1); } + } - for (b = 0; b < layer2_size; b++) + for (b = 0; b < layer2_size; b++) { for (a = 0; a < layerc_size; a++) { sync[a + b * layerc_size].weight = random(-0.1, 0.1) + random(-0.1, 0.1) + random(-0.1, 0.1); } + } } else { - for (b = 0; b < layer2_size; b++) + for (b = 0; b < layer2_size; b++) { for (a = 0; a < layer1_size; a++) { syn1[a + b * layer1_size].weight = random(-0.1, 0.1) + random(-0.1, 0.1) + random(-0.1, 0.1); } + } } - long long aa; - for (aa = 0; aa < direct_size; aa++) syn_d[aa] = 0; + int64 aa; + for (aa = 0; aa < direct_size; aa++) { + syn_d[aa] = 0; + } if (bptt > 0) { - bptt_history = (int *)calloc((bptt + bptt_block + 10), sizeof(int)); - for (a = 0; a < bptt + bptt_block; a++) bptt_history[a] = -1; - bptt_hidden = (neuron *)calloc((bptt + bptt_block + 1) * layer1_size, - sizeof(neuron)); + bptt_history = reinterpret_cast(calloc((bptt + bptt_block + 10), + sizeof(int))); + for (a = 0; a < bptt + bptt_block; a++) { + bptt_history[a] = -1; + } + bptt_hidden = reinterpret_cast(calloc( + (bptt + bptt_block + 1) * layer1_size, sizeof(neuron))); for (a = 0; a < (bptt + bptt_block) * layer1_size; a++) { bptt_hidden[a].ac = 0; bptt_hidden[a].er = 0; @@ -475,11 +497,13 @@ void CRnnLM::initNet() { b = 0; if (old_classes) { // old classes - for (i = 0; i < vocab_size; i++) b += vocab[i].cn; for (i = 0; i < vocab_size; i++) { - df+= vocab[i].cn / (double)b; + b += vocab[i].cn; + } + for (i = 0; i < vocab_size; i++) { + df += vocab[i].cn / static_cast(b); if (df > 1) df = 1; - if (df > (a + 1) / (double)class_size) { + if (df > (a + 1) / static_cast(class_size)) { vocab[i].class_index = a; if (a < class_size - 1) a++; } else { @@ -487,14 +511,18 @@ void CRnnLM::initNet() { } } } else { // new classes - for (i = 0; i < vocab_size; i++) b += vocab[i].cn; - for (i = 0; i < vocab_size; i++) dd += sqrt(vocab[i].cn / (double)b); for (i = 0; i < vocab_size; i++) { - df += sqrt(vocab[i].cn / (double)b) / dd; + b += vocab[i].cn; + } + for (i = 0; i < vocab_size; i++) { + dd += sqrt(vocab[i].cn / static_cast(b)); + } + for (i = 0; i < vocab_size; i++) { + df += sqrt(vocab[i].cn / static_cast(b)) / dd; if (df > 1) df = 1; - if (df > (a + 1) / (double)class_size) { + if (df > (a + 1) / static_cast(class_size)) { vocab[i].class_index = a; - if (a < class_size-1) a++; + if (a < class_size - 1) a++; } else { vocab[i].class_index = a; } @@ -504,14 +532,14 @@ void CRnnLM::initNet() { // allocate auxiliary class variables (for faster search when // normalizing probability at output layer) - class_words = (int **)calloc(class_size, sizeof(int *)); - class_cn = (int *)calloc(class_size, sizeof(int)); - class_max_cn = (int *)calloc(class_size, sizeof(int)); + class_words = reinterpret_cast(calloc(class_size, sizeof(int *))); + class_cn = reinterpret_cast(calloc(class_size, sizeof(int))); + class_max_cn = reinterpret_cast(calloc(class_size, sizeof(int))); for (i = 0; i < class_size; i++) { class_cn[i] = 0; class_max_cn[i] = 10; - class_words[i] = (int *)calloc(class_max_cn[i], sizeof(int)); + class_words[i] = reinterpret_cast(calloc(class_max_cn[i], sizeof(int))); } for (i = 0; i < vocab_size; i++) { @@ -520,8 +548,8 @@ void CRnnLM::initNet() { class_cn[cl]++; if (class_cn[cl] + 2 >= class_max_cn[cl]) { class_max_cn[cl] += 10; - class_words[cl] = (int *)realloc(class_words[cl], - class_max_cn[cl] * sizeof(int)); + class_words[cl] = reinterpret_cast(realloc(class_words[cl], + class_max_cn[cl] * sizeof(int))); } } } @@ -593,7 +621,7 @@ void CRnnLM::restoreNet() { // will read whole network structure fscanf(fi, "%d", &layer2_size); if (ver > 5) { goToDelimiter(':', fi); - fscanf(fi, "%lld", &direct_size); + fscanf(fi, "%ld", &direct_size); } if (ver > 6) { goToDelimiter(':', fi); @@ -732,14 +760,14 @@ void CRnnLM::restoreNet() { // will read whole network structure } if (filetype == TEXT) { goToDelimiter(':', fi); // direct conenctions - long long aa; + int64 aa; for (aa = 0; aa < direct_size; aa++) { fscanf(fi, "%lf", &d); syn_d[aa] = d; } } if (filetype == BINARY) { - long long aa; + int64 aa; for (aa = 0; aa < direct_size; aa++) { fread(&fl, 4, 1, fi); syn_d[aa] = fl; @@ -765,15 +793,20 @@ void CRnnLM::netReset() { // cleans hidden layer activation + bptt history copyHiddenLayerToInput(); if (bptt > 0) { - for (a = 1; a < bptt + bptt_block; a++) bptt_history[a] = 0; - for (a = bptt + bptt_block-1; a > 1; a--) + for (a = 1; a < bptt + bptt_block; a++) { + bptt_history[a] = 0; + } + for (a = bptt + bptt_block - 1; a > 1; a--) { for (b = 0; b < layer1_size; b++) { bptt_hidden[a * layer1_size + b].ac = 0; bptt_hidden[a * layer1_size + b].er = 0; + } } } - for (a = 0; a < MAX_NGRAM_ORDER; a++) history[a] = 0; + for (a = 0; a < MAX_NGRAM_ORDER; a++) { + history[a] = 0; + } } void CRnnLM::matrixXvector(struct neuron *dest, struct neuron *srcvec, @@ -796,35 +829,35 @@ void CRnnLM::matrixXvector(struct neuron *dest, struct neuron *srcvec, val8 = 0; for (a = from2; a < to2; a++) { - val1 += srcvec[a].ac * srcmatrix[a+(b*8+from+0)*matrix_width].weight; - val2 += srcvec[a].ac * srcmatrix[a+(b*8+from+1)*matrix_width].weight; - val3 += srcvec[a].ac * srcmatrix[a+(b*8+from+2)*matrix_width].weight; - val4 += srcvec[a].ac * srcmatrix[a+(b*8+from+3)*matrix_width].weight; - - val5 += srcvec[a].ac * srcmatrix[a+(b*8+from+4)*matrix_width].weight; - val6 += srcvec[a].ac * srcmatrix[a+(b*8+from+5)*matrix_width].weight; - val7 += srcvec[a].ac * srcmatrix[a+(b*8+from+6)*matrix_width].weight; - val8 += srcvec[a].ac * srcmatrix[a+(b*8+from+7)*matrix_width].weight; + val1 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 0) * matrix_width].weight; + val2 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 1) * matrix_width].weight; + val3 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 2) * matrix_width].weight; + val4 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 3) * matrix_width].weight; + + val5 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 4) * matrix_width].weight; + val6 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 5) * matrix_width].weight; + val7 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 6) * matrix_width].weight; + val8 += srcvec[a].ac * srcmatrix[a + (b * 8 + from + 7) * matrix_width].weight; } - dest[b*8+from+0].ac += val1; - dest[b*8+from+1].ac += val2; - dest[b*8+from+2].ac += val3; - dest[b*8+from+3].ac += val4; - - dest[b*8+from+4].ac += val5; - dest[b*8+from+5].ac += val6; - dest[b*8+from+6].ac += val7; - dest[b*8+from+7].ac += val8; + dest[b * 8 + from + 0].ac += val1; + dest[b * 8 + from + 1].ac += val2; + dest[b * 8 + from + 2].ac += val3; + dest[b * 8 + from + 3].ac += val4; + + dest[b * 8 + from + 4].ac += val5; + dest[b * 8 + from + 5].ac += val6; + dest[b * 8 + from + 6].ac += val7; + dest[b * 8 + from + 7].ac += val8; } - for (b = b*8; b < to-from; b++) { + for (b = b * 8; b < to - from; b++) { for (a = from2; a < to2; a++) { dest[b+from].ac += - srcvec[a].ac * srcmatrix[a+(b+from)*matrix_width].weight; + srcvec[a].ac * srcmatrix[a + (b + from) * matrix_width].weight; } } } else { // er mod - for (a = 0; a < (to2-from2)/8; a++) { + for (a = 0; a < (to2 - from2) / 8; a++) { val1 = 0; val2 = 0; val3 = 0; @@ -836,25 +869,25 @@ void CRnnLM::matrixXvector(struct neuron *dest, struct neuron *srcvec, val8 = 0; for (b = from; b < to; b++) { - val1 += srcvec[b].er * srcmatrix[a*8+from2+0+b*matrix_width].weight; - val2 += srcvec[b].er * srcmatrix[a*8+from2+1+b*matrix_width].weight; - val3 += srcvec[b].er * srcmatrix[a*8+from2+2+b*matrix_width].weight; - val4 += srcvec[b].er * srcmatrix[a*8+from2+3+b*matrix_width].weight; - - val5 += srcvec[b].er * srcmatrix[a*8+from2+4+b*matrix_width].weight; - val6 += srcvec[b].er * srcmatrix[a*8+from2+5+b*matrix_width].weight; - val7 += srcvec[b].er * srcmatrix[a*8+from2+6+b*matrix_width].weight; - val8 += srcvec[b].er * srcmatrix[a*8+from2+7+b*matrix_width].weight; + val1 += srcvec[b].er * srcmatrix[a * 8 + from2 + 0 + b * matrix_width].weight; + val2 += srcvec[b].er * srcmatrix[a * 8 + from2 + 1 + b * matrix_width].weight; + val3 += srcvec[b].er * srcmatrix[a * 8 + from2 + 2 + b * matrix_width].weight; + val4 += srcvec[b].er * srcmatrix[a * 8 + from2 + 3 + b * matrix_width].weight; + + val5 += srcvec[b].er * srcmatrix[a * 8 + from2 + 4 + b * matrix_width].weight; + val6 += srcvec[b].er * srcmatrix[a * 8 + from2 + 5 + b * matrix_width].weight; + val7 += srcvec[b].er * srcmatrix[a * 8 + from2 + 6 + b * matrix_width].weight; + val8 += srcvec[b].er * srcmatrix[a * 8 + from2 + 7 + b * matrix_width].weight; } - dest[a*8+from2+0].er += val1; - dest[a*8+from2+1].er += val2; - dest[a*8+from2+2].er += val3; - dest[a*8+from2+3].er += val4; - - dest[a*8+from2+4].er += val5; - dest[a*8+from2+5].er += val6; - dest[a*8+from2+6].er += val7; - dest[a*8+from2+7].er += val8; + dest[a * 8 + from2 + 0].er += val1; + dest[a * 8 + from2 + 1].er += val2; + dest[a * 8 + from2 + 2].er += val3; + dest[a * 8 + from2 + 3].er += val4; + + dest[a * 8 + from2 + 4].er += val5; + dest[a * 8 + from2 + 5].er += val6; + dest[a * 8 + from2 + 6].er += val7; + dest[a * 8 + from2 + 7].er += val8; } for (a = a * 8; a < to2 - from2; a++) { @@ -899,15 +932,19 @@ void CRnnLM::computeNet(int last_word, int word) { if (last_word != -1) neu0[last_word].ac = 1; // propagate 0->1 - for (a = 0; a < layer1_size; a++) neu1[a].ac = 0; - for (a = 0; a < layerc_size; a++) neuc[a].ac = 0; + for (a = 0; a < layer1_size; a++) { + neu1[a].ac = 0; + } + for (a = 0; a < layerc_size; a++) { + neuc[a].ac = 0; + } matrixXvector(neu1, neu0, syn0, layer0_size, 0, layer1_size, - layer0_size-layer1_size, layer0_size, 0); + layer0_size - layer1_size, layer0_size, 0); for (b = 0; b < layer1_size; b++) { a = last_word; - if (a != -1) neu1[b].ac += neu0[a].ac * syn0[a+b*layer0_size].weight; + if (a != -1) neu1[b].ac += neu0[a].ac * syn0[a + b * layer0_size].weight; } // activate 1 --sigmoid @@ -931,7 +968,9 @@ void CRnnLM::computeNet(int last_word, int word) { } // 1->2 class - for (b = vocab_size; b < layer2_size; b++) neu2[b].ac = 0; + for (b = vocab_size; b < layer2_size; b++) { + neu2[b].ac = 0; + } if (layerc_size > 0) { matrixXvector(neu2, neuc, sync, layerc_size, @@ -943,20 +982,23 @@ void CRnnLM::computeNet(int last_word, int word) { // apply direct connections to classes if (direct_size > 0) { - unsigned long long hash[MAX_NGRAM_ORDER]; + uint64 hash[MAX_NGRAM_ORDER]; // this will hold pointers to syn_d that contains hash parameters - for (a = 0; a < direct_order; a++) hash[a] = 0; + for (a = 0; a < direct_order; a++) { + hash[a] = 0; + } for (a = 0; a < direct_order; a++) { b = 0; - if (a > 0) if (history[a-1] == -1) break; + if (a > 0) if (history[a - 1] == -1) break; // if OOV was in history, do not use this N-gram feature and higher orders - hash[a] = PRIMES[0]*PRIMES[1]; + hash[a] = PRIMES[0] * PRIMES[1]; - for (b = 1; b <= a; b++) + for (b = 1; b <= a; b++) { hash[a] += PRIMES[(a * PRIMES[b] + b) % PRIMES_SIZE] - * (unsigned long long)(history[b - 1] + 1); + * static_cast(history[b - 1] + 1); + } // update hash value based on words from the history hash[a] = hash[a] % (direct_size / 2); @@ -965,7 +1007,7 @@ void CRnnLM::computeNet(int last_word, int word) { } for (a = vocab_size; a < layer2_size; a++) { - for (b = 0; b < direct_order; b++) + for (b = 0; b < direct_order; b++) { if (hash[b]) { neu2[a].ac += syn_d[hash[b]]; // apply current parameter and move to the next one @@ -974,6 +1016,7 @@ void CRnnLM::computeNet(int last_word, int word) { } else { break; } + } } } @@ -986,7 +1029,9 @@ void CRnnLM::computeNet(int last_word, int word) { sum+= val; neu2[a].ac = val; } - for (a = vocab_size; a < layer2_size; a++) neu2[a].ac /= sum; + for (a = vocab_size; a < layer2_size; a++) { + neu2[a].ac /= sum; + } // output layer activations now sum exactly to 1 if (gen > 0) return; // if we generate words, we don't know what current word @@ -996,8 +1041,9 @@ void CRnnLM::computeNet(int last_word, int word) { // 1->2 word if (word != -1) { - for (c = 0; c < class_cn[vocab[word].class_index]; c++) + for (c = 0; c < class_cn[vocab[word].class_index]; c++) { neu2[class_words[vocab[word].class_index][c]].ac = 0; + } if (layerc_size > 0) { matrixXvector(neu2, neuc, sync, layerc_size, class_words[vocab[word].class_index][0], @@ -1015,20 +1061,23 @@ void CRnnLM::computeNet(int last_word, int word) { // apply direct connections to words if (word != -1) if (direct_size > 0) { - unsigned long long hash[MAX_NGRAM_ORDER]; + uint64 hash[MAX_NGRAM_ORDER]; - for (a = 0; a < direct_order; a++) hash[a] = 0; + for (a = 0; a < direct_order; a++) { + hash[a] = 0; + } for (a = 0; a < direct_order; a++) { b = 0; - if (a > 0) if (history[a-1] == -1) break; + if (a > 0) if (history[a - 1] == -1) break; hash[a] = PRIMES[0] * PRIMES[1] * - (unsigned long long)(vocab[word].class_index+1); + static_cast(vocab[word].class_index + 1); - for (b = 1; b <= a; b++) + for (b = 1; b <= a; b++) { hash[a] += PRIMES[(a * PRIMES[b] + b) % PRIMES_SIZE] - * (unsigned long long)(history[b - 1] + 1); + * static_cast(history[b - 1] + 1); + } hash[a] = (hash[a] % (direct_size / 2)) + (direct_size) / 2; } @@ -1056,8 +1105,9 @@ void CRnnLM::computeNet(int last_word, int word) { sum+= val; neu2[a].ac = val; } - for (c = 0; c < class_cn[vocab[word].class_index]; c++) + for (c = 0; c < class_cn[vocab[word].class_index]; c++) { neu2[class_words[vocab[word].class_index][c]].ac /= sum; + } } } diff --git a/src/lm/mikolov-rnnlm-lib.h b/src/lm/mikolov-rnnlm-lib.h index 36d88a0a5d0..fb9c340416b 100644 --- a/src/lm/mikolov-rnnlm-lib.h +++ b/src/lm/mikolov-rnnlm-lib.h @@ -143,7 +143,7 @@ class CRnnLM { int layerc_size; int layer2_size; - long long direct_size; + int64 direct_size; int direct_order; int history[MAX_NGRAM_ORDER];