diff --git a/moses/LM/IRST.cpp b/moses/LM/IRST.cpp index caa3f6a16..f70530231 100644 --- a/moses/LM/IRST.cpp +++ b/moses/LM/IRST.cpp @@ -36,6 +36,7 @@ using namespace irstlm; #include "moses/Phrase.h" #include "moses/InputFileStream.h" #include "moses/StaticData.h" +#include "moses/TranslationTask.h" using namespace std; @@ -285,6 +286,9 @@ FFState* LanguageModelIRST::EvaluateWhenAppliedWithContext(ttasksptr const& ttas return ret.release(); } + //get the context_weight map here + std::map context_weight = ttasks->GetContextWeights(); + //[begin, end) in STL-like fashion. const int begin = (const int) hypo.GetCurrTargetWordsRange().GetStartPos(); const int end = (const int) hypo.GetCurrTargetWordsRange().GetEndPos() + 1; diff --git a/moses/TranslationModel/UG/mm/ug_sampling_bias.cc b/moses/TranslationModel/UG/mm/ug_sampling_bias.cc index 2944f49e8..7ac540045 100644 --- a/moses/TranslationModel/UG/mm/ug_sampling_bias.cc +++ b/moses/TranslationModel/UG/mm/ug_sampling_bias.cc @@ -60,6 +60,10 @@ namespace Moses init(context_weights, docname2docid); } + std::map& SamplingBias::getBiasMap() { + return m_bias_map; + } + void DocumentBias ::init_from_json @@ -96,6 +100,7 @@ namespace Moses << x.first << " " << x.second << std::endl; } } + m_bias_map = bias; init(bias, docname2docid); // using xmlrpc_parse_json didn't always work (parser errors) diff --git a/moses/TranslationModel/UG/mm/ug_sampling_bias.h b/moses/TranslationModel/UG/mm/ug_sampling_bias.h index 55eec3854..172bb60db 100644 --- a/moses/TranslationModel/UG/mm/ug_sampling_bias.h +++ b/moses/TranslationModel/UG/mm/ug_sampling_bias.h @@ -20,6 +20,8 @@ namespace Moses public: int loglevel; std::ostream* log; + std::map m_bias_map; //Map to store the biasmap as you get it from the server + std::map& getBiasMap(); virtual float operator[](id_type const ID) const = 0; // returns (unnormalized bias) for the class of item ID diff --git a/moses/TranslationModel/UG/mmsapt.cpp b/moses/TranslationModel/UG/mmsapt.cpp index 5eb5c6785..f6f9fff50 100644 --- a/moses/TranslationModel/UG/mmsapt.cpp +++ b/moses/TranslationModel/UG/mmsapt.cpp @@ -791,6 +791,9 @@ namespace Moses = btfix.SetupDocumentBias(m_bias_server, context_words, m_bias_log); context->bias->loglevel = m_bias_loglevel; context->bias->log = m_bias_log; + //Reset the bias in the ttaskptr so that other functions + //so that other functions can utilize the biases; + ttask->ReSetContextWeights(context->bias->getBiasMap()); } if (!context->cache1) context->cache1.reset(new pstats::cache_t); if (!context->cache2) context->cache2.reset(new pstats::cache_t); diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp index dd9fcbc52..0c6e6c69e 100644 --- a/moses/TranslationTask.cpp +++ b/moses/TranslationTask.cpp @@ -36,6 +36,13 @@ TranslationTask::GetContextWeights() const return m_context_weights; } +void +TranslationTask +::ReSetContextWeights(std::map const& new_weights) +{ + m_context_weights = new_weights; +} + void TranslationTask ::SetContextString(std::string const& context) diff --git a/moses/TranslationTask.h b/moses/TranslationTask.h index bf1add124..f37bad535 100644 --- a/moses/TranslationTask.h +++ b/moses/TranslationTask.h @@ -118,6 +118,8 @@ public: std::map const& GetContextWeights() const; void SetContextWeights(std::string const& context_weights); + void ReSetContextWeights(std::map const& new_weights); + protected: boost::shared_ptr m_source;