Skip to content

Commit

Permalink
fix parser n_classes bug HIT-SCIR#129 , tiny fix on meaningless unsig…
Browse files Browse the repository at this point in the history
…ned comparison
  • Loading branch information
Oneplus committed Apr 12, 2016
1 parent 806e1e3 commit f86c1b9
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/parser.n/classifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/parser.n/parser_frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/smartmap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ class IndexableSmartMap : public SmartMap<int32_t> {
* @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<int32_t>::_key_buffer + entries[i];
} else {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/strutils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit f86c1b9

Please sign in to comment.