Răsfoiți Sursa

Print error message for invalid pretrained model files

Summary: Print an error message for invalid pretrained models (i.e. non quantized models which have a pruneidx_idx_ field different than -1).

Reviewed By: cpuhrsch

Differential Revision: D6097450

fbshipit-source-id: 203d1eeab03a3f8acb59926daa5ae2f54b7f236b
Edouard Grave 8 ani în urmă
părinte
comite
431c9e2a9b
2 a modificat fișierele cu 10 adăugiri și 1 ștergeri
  1. 1 0
      src/dictionary.h
  2. 9 1
      src/fasttext.cc

+ 1 - 0
src/dictionary.h

@@ -104,6 +104,7 @@ class Dictionary {
                     std::minstd_rand&) const;
     void threshold(int64_t, int64_t);
     void prune(std::vector<int32_t>&);
+    bool isPruned() { return pruneidx_size_ >= 0; }
 };
 
 }

+ 9 - 1
src/fasttext.cc

@@ -171,6 +171,13 @@ void FastText::loadModel(std::istream& in) {
     input_->load(in);
   }
 
+  if (!quant_input && dict_->isPruned()) {
+    std::cerr << "Invalid model file.\n"
+              << "Please download the updated model from www.fasttext.cc.\n"
+              << "See issue #332 on Github for more information.\n";
+    exit(1);
+  }
+
   in.read((char*) &args_->qout, sizeof(bool));
   if (quant_ && args_->qout) {
     qoutput_->load(in);
@@ -221,7 +228,8 @@ std::vector<int32_t> FastText::selectEmbeddings(int32_t cutoff) const {
 
 void FastText::quantize(std::shared_ptr<Args> qargs) {
   if (qargs->output.empty()) {
-      std::cerr<<"No model provided!"<<std::endl; exit(1);
+    std::cerr<<"No model provided!"<<std::endl;
+    exit(1);
   }
   loadModel(qargs->output + ".bin");