update probing pt version. Change config format

This commit is contained in:
Hieu Hoang 2016-06-15 12:56:36 +01:00
parent fbb8b30681
commit 3ed2bf1a52
4 changed files with 62 additions and 18 deletions

View File

@ -10,7 +10,7 @@
namespace Moses2
{
#define API_VERSION 10
#define API_VERSION 11
//Hash table entry
struct Entry

View File

@ -1,4 +1,7 @@
#include <unordered_map>
#include "quering.hh"
#include "util/exception.hh"
#include "../Util2.h"
namespace Moses2
{
@ -15,28 +18,54 @@ QueryEngine::QueryEngine(const char * filepath)
read_map(source_vocabids, path_to_source_vocabid.c_str());
//Read config file
std::string line;
std::unordered_map<std::string, std::string> keyValue;
std::ifstream config((basepath + "/config").c_str());
std::string line;
while (getline(config, line)) {
std::vector<std::string> toks = Moses2::Tokenize(line, "\t");
UTIL_THROW_IF2(toks.size() != 2, "Wrong config format:" << line);
keyValue[ toks[0] ] = toks[1];
}
bool found;
//Check API version:
getline(config, line);
int version = atoi(line.c_str());
if (version != API_VERSION) {
int version;
found = Get(keyValue, "API_VERSION", version);
if (!found || version != API_VERSION) {
std::cerr << "The ProbingPT API has changed. " << version << "!="
<< API_VERSION << " Please rebinarize your phrase tables." << std::endl;
exit(EXIT_FAILURE);
}
//Get tablesize.
getline(config, line);
int tablesize = atoi(line.c_str());
int tablesize;
found = Get(keyValue, "uniq_entries", tablesize);
if (!found) {
std::cerr << "uniq_entries not found" << std::endl;
exit(EXIT_FAILURE);
}
//Number of scores
getline(config, line);
num_scores = atoi(line.c_str());
found = Get(keyValue, "num_scores", num_scores);
if (!found) {
std::cerr << "num_scores not found" << std::endl;
exit(EXIT_FAILURE);
}
//How may scores from lex reordering models
getline(config, line);
num_lex_scores = atoi(line.c_str());
found = Get(keyValue, "num_lex_scores", num_lex_scores);
if (!found) {
std::cerr << "num_lex_scores not found" << std::endl;
exit(EXIT_FAILURE);
}
// have the scores been log() and FloorScore()?
getline(config, line);
logProb = atoi(line.c_str());
found = Get(keyValue, "log_prob", logProb);
if (!found) {
std::cerr << "logProb not found" << std::endl;
exit(EXIT_FAILURE);
}
config.close();

View File

@ -1,5 +1,6 @@
#pragma once
#include <unordered_map>
#include <sys/stat.h> //For finding size of file
#include "vocabid.hh"
#include <algorithm> //toLower
@ -7,6 +8,7 @@
#include "probing_hash_utils.hh"
#include "hash.hh" //Includes line splitter
#include "line_splitter.hh"
#include "../Util2.h"
namespace Moses2
{
@ -39,6 +41,19 @@ public:
uint64_t getKey(uint64_t source_phrase[], size_t size) const;
template<typename T>
inline bool Get(const std::unordered_map<std::string, std::string> &keyValue, const std::string &sought, T &found) const
{
std::unordered_map<std::string, std::string>::const_iterator iter = keyValue.find(sought);
if (iter == keyValue.end()) {
return false;
}
const std::string &foundStr = iter->second;
found = Scan<T>(foundStr);
return true;
}
};
}

View File

@ -152,11 +152,11 @@ void createProbingPT(const std::string &phrasetable_path,
//Write configfile
std::ofstream configfile;
configfile.open((basepath + "/config").c_str());
configfile << API_VERSION << '\n';
configfile << uniq_entries << '\n';
configfile << num_scores << '\n';
configfile << num_lex_scores << '\n';
configfile << log_prob << '\n';
configfile << "API_VERSION\t" << API_VERSION << '\n';
configfile << "uniq_entries\t" << uniq_entries << '\n';
configfile << "num_scores\t" << num_scores << '\n';
configfile << "num_lex_scores\t" << num_lex_scores << '\n';
configfile << "log_prob\t" << log_prob << '\n';
configfile.close();
}