Allow user to specify whether PhraseDictionaryMemoryPerSentenceOnDemand are probability values or not

This commit is contained in:
Lane Schwartz 2017-01-02 14:22:26 -06:00
parent 76a8850487
commit a18b6676b1
2 changed files with 9 additions and 3 deletions

View File

@ -8,7 +8,7 @@ using namespace std;
namespace Moses namespace Moses
{ {
PhraseDictionaryMemoryPerSentenceOnDemand::PhraseDictionaryMemoryPerSentenceOnDemand(const std::string &line) PhraseDictionaryMemoryPerSentenceOnDemand::PhraseDictionaryMemoryPerSentenceOnDemand(const std::string &line)
: PhraseDictionary(line, true) : PhraseDictionary(line, true), m_valuesAreProbabilities(true)
{ {
ReadParameters(); ReadParameters();
} }
@ -67,8 +67,10 @@ void PhraseDictionaryMemoryPerSentenceOnDemand::InitializeForInput(ttasksptr con
// score for this phrase table // score for this phrase table
vector<float> scores = Tokenize<float>(toks[2]); vector<float> scores = Tokenize<float>(toks[2]);
std::transform(scores.begin(), scores.end(), scores.begin(),TransformScore); if (m_valuesAreProbabilities) {
std::transform(scores.begin(), scores.end(), scores.begin(),FloorScore); std::transform(scores.begin(), scores.end(), scores.begin(),TransformScore);
std::transform(scores.begin(), scores.end(), scores.begin(),FloorScore);
}
target->GetScoreBreakdown().PlusEquals(this, scores); target->GetScoreBreakdown().PlusEquals(this, scores);
// score of all other ff when this rule is being loaded // score of all other ff when this rule is being loaded
@ -129,6 +131,8 @@ PhraseDictionaryMemoryPerSentenceOnDemand::SetParameter(const std::string& key,
{ {
if (key == "path") { if (key == "path") {
UTIL_THROW(util::Exception, "PhraseDictionaryMemoryPerSentenceOnDemand does not support key \"path\"."); UTIL_THROW(util::Exception, "PhraseDictionaryMemoryPerSentenceOnDemand does not support key \"path\".");
} else if (key == "valuesAreProbabilities") {
m_valuesAreProbabilities = Scan<bool>(value);
} else { } else {
PhraseDictionary::SetParameter(key, value); PhraseDictionary::SetParameter(key, value);
} }

View File

@ -39,6 +39,8 @@ protected:
typedef boost::unordered_map<Phrase, TargetPhraseCollection::shared_ptr> Coll; typedef boost::unordered_map<Phrase, TargetPhraseCollection::shared_ptr> Coll;
mutable boost::thread_specific_ptr<Coll> m_coll; mutable boost::thread_specific_ptr<Coll> m_coll;
bool m_valuesAreProbabilities;
Coll &GetColl() const; Coll &GetColl() const;
}; };