Skip to content

Commit

Permalink
More accurate error messages on invalid examples (facebookresearch#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
ledw authored Jan 9, 2018
1 parent 57c6212 commit 66a5d5b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ InternDataHandler::InternDataHandler(shared_ptr<Args> args) {
args_= args;
}

void InternDataHandler::errorOnZeroExample(const string& fileName) {
std::cerr << "ERROR: File '" << fileName
<< "' does not contain any valid example.\n"
<< "Please check: is the file empty? "
<< "Do the examples contain proper feature and label according to the trainMode? "
<< "If your examples are unlabeled, try to set trainMode=5.\n";
exit(EXIT_FAILURE);
}

void InternDataHandler::loadFromFile(
const string& fileName,
shared_ptr<DataParser> parser) {
Expand Down Expand Up @@ -62,8 +71,7 @@ void InternDataHandler::loadFromFile(
cout << "Total number of examples loaded : " << examples_.size() << endl;
size_ = examples_.size();
if (size_ == 0) {
std::cerr << "ERROR: File '" << fileName << "' is empty." << std::endl;
exit(EXIT_FAILURE);
errorOnZeroExample(fileName);
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class InternDataHandler {

size_t getSize() const { return size_; };

void errorOnZeroExample(const std::string& fileName);


protected:
static const int32_t MAX_VOCAB_SIZE = 10000000;
Expand Down
3 changes: 1 addition & 2 deletions src/doc_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ void LayerDataHandler::loadFromFile(
cout << "Total number of examples loaded : " << examples_.size() << endl;
size_ = examples_.size();
if (size_ == 0) {
std::cerr << "ERROR: File '" << fileName << "' is empty." << std::endl;
exit(EXIT_FAILURE);
errorOnZeroExample(fileName);
}
}

Expand Down

0 comments on commit 66a5d5b

Please sign in to comment.