diff --git a/src/parser.n/classifier.cpp b/src/parser.n/classifier.cpp index 34f9cc2ab..21e062a61 100644 --- a/src/parser.n/classifier.cpp +++ b/src/parser.n/classifier.cpp @@ -279,8 +279,8 @@ void NeuralNetworkClassifier::compute_gradient( /*arma::uvec classes_mask = arma::find(Y >= 0);*/ Eigen::VectorXd __ = (Y.array() >= 0).select( - Eigen::VectorXd::Ones(hidden_layer_size), - Eigen::VectorXd::Zero(hidden_layer_size)); + Eigen::VectorXd::Ones(nr_classes), + Eigen::VectorXd::Zero(nr_classes)); double best = output(opt_class); output = __.asDiagonal() * Eigen::VectorXd((output.array() - best).exp()); double sum1 = output(correct_class); diff --git a/src/parser.n/parser_frontend.cpp b/src/parser.n/parser_frontend.cpp index 935f9873d..f99ec64c2 100644 --- a/src/parser.n/parser_frontend.cpp +++ b/src/parser.n/parser_frontend.cpp @@ -506,7 +506,9 @@ void NeuralNetworkParserFrontend::test(void) { size_t corr_heads = 0, corr_deprels = 0, nr_tokens = 0; timer t; - while (inst = reader.next()) { + while (true) { + inst = reader.next(); + if (inst == NULL) { break; } predict((*inst), heads, deprels); writer.write(*inst, heads, deprels); diff --git a/src/utils/smartmap.hpp b/src/utils/smartmap.hpp index b0123e33c..3f15fc550 100644 --- a/src/utils/smartmap.hpp +++ b/src/utils/smartmap.hpp @@ -648,7 +648,7 @@ class IndexableSmartMap : public SmartMap { * @return const char * pointer to the key */ const char* at(const size_t& i) const { - if (i >= 0 && i < _num_entries) { + if (i < _num_entries) { return SmartMap::_key_buffer + entries[i]; } else { return 0; diff --git a/src/utils/strutils.hpp b/src/utils/strutils.hpp index dd78a6302..8c485c08b 100644 --- a/src/utils/strutils.hpp +++ b/src/utils/strutils.hpp @@ -16,7 +16,7 @@ inline void trim(std::string& str) { size_t len = str.size(); if (len == 0) { return; } - while (len -1 >=0 && (str[len-1] == ' ' + while (len >= 1 && (str[len-1] == ' ' || str[len-1]=='\t' || str[len-1] == '\r' || str[len-1] == '\n')) {