فهرست منبع

Fix small bug in predict

Summary: predictions.clear() should be called earlier.

Reviewed By: ajoulin

Differential Revision: D5366752

fbshipit-source-id: 30be9e59dd44fbb3ec28b925803114fe1d7e6ad9
Edouard Grave 8 سال پیش
والد
کامیت
0fff0b8b95
1فایلهای تغییر یافته به همراه1 افزوده شده و 1 حذف شده
  1. 1 1
      src/fasttext.cc

+ 1 - 1
src/fasttext.cc

@@ -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)));
   }