Skip to content

Commit

Permalink
Fix small bug in predict
Browse files Browse the repository at this point in the history
Summary: predictions.clear() should be called earlier.

Reviewed By: ajoulin

Differential Revision: D5366752

fbshipit-source-id: 30be9e59dd44fbb3ec28b925803114fe1d7e6ad9
  • Loading branch information
Edouard Grave authored and facebook-github-bot committed Jul 4, 2017
1 parent 6d2c453 commit 0fff0b8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/fasttext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ void FastText::test(std::istream& in, int32_t k) {
void FastText::predict(std::istream& in, int32_t k,
std::vector<std::pair<real,std::string>>& predictions) const {
std::vector<int32_t> words, labels;
predictions.clear();
dict_->getLine(in, words, labels, model_->rng);
if (words.empty()) return;
Vector hidden(args_->dim);
Vector output(dict_->nlabels());
std::vector<std::pair<real,int32_t>> modelPredictions;
model_->predict(words, k, modelPredictions, hidden, output);
predictions.clear();
for (auto it = modelPredictions.cbegin(); it != modelPredictions.cend(); it++) {
predictions.push_back(std::make_pair(it->first, dict_->getLabel(it->second)));
}
Expand Down

0 comments on commit 0fff0b8

Please sign in to comment.