mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-24 20:32:59 +03:00
Enable the bias weights to be (re)set by the server.
This commit is contained in:
parent
5a0168a6fa
commit
47a488767e
@ -36,6 +36,7 @@ using namespace irstlm;
|
|||||||
#include "moses/Phrase.h"
|
#include "moses/Phrase.h"
|
||||||
#include "moses/InputFileStream.h"
|
#include "moses/InputFileStream.h"
|
||||||
#include "moses/StaticData.h"
|
#include "moses/StaticData.h"
|
||||||
|
#include "moses/TranslationTask.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -285,6 +286,9 @@ FFState* LanguageModelIRST::EvaluateWhenAppliedWithContext(ttasksptr const& ttas
|
|||||||
return ret.release();
|
return ret.release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//get the context_weight map here
|
||||||
|
std::map<std::string, float> context_weight = ttasks->GetContextWeights();
|
||||||
|
|
||||||
//[begin, end) in STL-like fashion.
|
//[begin, end) in STL-like fashion.
|
||||||
const int begin = (const int) hypo.GetCurrTargetWordsRange().GetStartPos();
|
const int begin = (const int) hypo.GetCurrTargetWordsRange().GetStartPos();
|
||||||
const int end = (const int) hypo.GetCurrTargetWordsRange().GetEndPos() + 1;
|
const int end = (const int) hypo.GetCurrTargetWordsRange().GetEndPos() + 1;
|
||||||
|
@ -60,6 +60,10 @@ namespace Moses
|
|||||||
init(context_weights, docname2docid);
|
init(context_weights, docname2docid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::string, float>& SamplingBias::getBiasMap() {
|
||||||
|
return m_bias_map;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DocumentBias
|
DocumentBias
|
||||||
::init_from_json
|
::init_from_json
|
||||||
@ -96,6 +100,7 @@ namespace Moses
|
|||||||
<< x.first << " " << x.second << std::endl;
|
<< x.first << " " << x.second << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_bias_map = bias;
|
||||||
init(bias, docname2docid);
|
init(bias, docname2docid);
|
||||||
|
|
||||||
// using xmlrpc_parse_json didn't always work (parser errors)
|
// using xmlrpc_parse_json didn't always work (parser errors)
|
||||||
|
@ -20,6 +20,8 @@ namespace Moses
|
|||||||
public:
|
public:
|
||||||
int loglevel;
|
int loglevel;
|
||||||
std::ostream* log;
|
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
|
virtual float
|
||||||
operator[](id_type const ID) const = 0;
|
operator[](id_type const ID) const = 0;
|
||||||
// returns (unnormalized bias) for the class of item ID
|
// returns (unnormalized bias) for the class of item ID
|
||||||
|
@ -791,6 +791,9 @@ namespace Moses
|
|||||||
= btfix.SetupDocumentBias(m_bias_server, context_words, m_bias_log);
|
= btfix.SetupDocumentBias(m_bias_server, context_words, m_bias_log);
|
||||||
context->bias->loglevel = m_bias_loglevel;
|
context->bias->loglevel = m_bias_loglevel;
|
||||||
context->bias->log = m_bias_log;
|
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->cache1) context->cache1.reset(new pstats::cache_t);
|
||||||
if (!context->cache2) context->cache2.reset(new pstats::cache_t);
|
if (!context->cache2) context->cache2.reset(new pstats::cache_t);
|
||||||
|
@ -36,6 +36,13 @@ TranslationTask::GetContextWeights() const
|
|||||||
return m_context_weights;
|
return m_context_weights;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TranslationTask
|
||||||
|
::ReSetContextWeights(std::map<std::string, float> const& new_weights)
|
||||||
|
{
|
||||||
|
m_context_weights = new_weights;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TranslationTask
|
TranslationTask
|
||||||
::SetContextString(std::string const& context)
|
::SetContextString(std::string const& context)
|
||||||
|
@ -118,6 +118,8 @@ public:
|
|||||||
|
|
||||||
std::map<std::string, float> const& GetContextWeights() const;
|
std::map<std::string, float> const& GetContextWeights() const;
|
||||||
void SetContextWeights(std::string const& context_weights);
|
void SetContextWeights(std::string const& context_weights);
|
||||||
|
void ReSetContextWeights(std::map<std::string, float> const& new_weights);
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
boost::shared_ptr<Moses::InputType> m_source;
|
boost::shared_ptr<Moses::InputType> m_source;
|
||||||
|
Loading…
Reference in New Issue
Block a user