Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Print error message for invalid pretrained model files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Edouard Grave authored and facebook-github-bot committed Oct 20, 2017
1 parent ebbd3bf commit 431c9e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/dictionary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
};

}
Expand Down
10 changes: 9 additions & 1 deletion src/fasttext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down

0 comments on commit 431c9e2

Please sign in to comment.