Enable the bias weights to be (re)set by the server.

This commit is contained in:
XapaJIaMnu 2015-06-25 13:12:33 +01:00
parent 5a0168a6fa
commit 47a488767e
6 changed files with 23 additions and 0 deletions

View File

@ -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<std::string, float> 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;

View File

@ -60,6 +60,10 @@ namespace Moses
init(context_weights, docname2docid);
}
std::map<std::string, float>& 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)

View File

@ -20,6 +20,8 @@ namespace Moses
public:
int loglevel;
std::ostream* log;
std::map<std::string, float> m_bias_map; //Map to store the biasmap as you get it from the server
std::map<std::string, float>& getBiasMap();
virtual float
operator[](id_type const ID) const = 0;
// returns (unnormalized bias) for the class of item ID

View File

@ -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);

View File

@ -36,6 +36,13 @@ TranslationTask::GetContextWeights() const
return m_context_weights;
}
void
TranslationTask
::ReSetContextWeights(std::map<std::string, float> const& new_weights)
{
m_context_weights = new_weights;
}
void
TranslationTask
::SetContextString(std::string const& context)

View File

@ -118,6 +118,8 @@ public:
std::map<std::string, float> const& GetContextWeights() const;
void SetContextWeights(std::string const& context_weights);
void ReSetContextWeights(std::map<std::string, float> const& new_weights);
protected:
boost::shared_ptr<Moses::InputType> m_source;