Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Germann <ugermann@inf.ed.ac.uk>2015-07-01 15:25:26 +0300
committerUlrich Germann <ugermann@inf.ed.ac.uk>2015-07-01 15:25:26 +0300
commit61067b4fa545623532aadea904d6d8c138d79f7a (patch)
tree9ed691e553a308298cce97e9772d026c749c991c
parent5fd19e576a4c05edb8657298a4fb24d0bc5b3e13 (diff)
parent6aa6131b844e5e08b4644692fa48c4d85fd2cf81 (diff)
Merge branch 'FF_ttptr' of http://github.com/moses-smt/mosesdecoder
-rw-r--r--moses/BaseManager.cpp5
-rw-r--r--moses/BaseManager.h1
-rw-r--r--moses/ExportInterface.cpp9
-rw-r--r--moses/FF/StatefulFeatureFunction.h8
-rw-r--r--moses/Hypothesis.cpp8
-rw-r--r--moses/LM/Base.cpp7
-rw-r--r--moses/LM/Base.h3
-rw-r--r--moses/LM/IRST.cpp11
-rw-r--r--moses/LM/IRST.h4
-rw-r--r--moses/Parameter.cpp1
-rw-r--r--moses/StaticData.cpp4
-rw-r--r--moses/TargetPhrase.cpp62
-rw-r--r--moses/TargetPhrase.h18
-rw-r--r--moses/TranslationModel/UG/mm/ug_bitext.h16
-rw-r--r--moses/TranslationModel/UG/mm/ug_sampling_bias.cc16
-rw-r--r--moses/TranslationModel/UG/mm/ug_sampling_bias.h7
-rw-r--r--moses/TranslationModel/UG/mmsapt.cpp32
-rw-r--r--moses/TranslationModel/UG/mmsapt.h3
-rw-r--r--moses/TranslationTask.cpp23
-rw-r--r--moses/TranslationTask.h6
20 files changed, 223 insertions, 21 deletions
diff --git a/moses/BaseManager.cpp b/moses/BaseManager.cpp
index ce1a5c5d9..609a6e9f5 100644
--- a/moses/BaseManager.cpp
+++ b/moses/BaseManager.cpp
@@ -27,6 +27,11 @@ BaseManager::GetSource() const
return m_source;
}
+const ttasksptr&
+BaseManager::GetTtask() const {
+ return m_ttask.lock();
+}
+
void
BaseManager::
OutputSearchGraphAsHypergraph(std::ostream& out) const
diff --git a/moses/BaseManager.h b/moses/BaseManager.h
index 422b61c1f..7367997ad 100644
--- a/moses/BaseManager.h
+++ b/moses/BaseManager.h
@@ -50,6 +50,7 @@ public:
//! the input sentence being decoded
const InputType& GetSource() const;
+ const ttasksptr& GetTtask() const;
virtual void Decode() = 0;
// outputs
diff --git a/moses/ExportInterface.cpp b/moses/ExportInterface.cpp
index c444e98c9..54121609b 100644
--- a/moses/ExportInterface.cpp
+++ b/moses/ExportInterface.cpp
@@ -215,6 +215,9 @@ batch_run()
std::string context_string;
params.SetParameter(context_string,"context-string",string(""));
+ std::string context_weights;
+ params.SetParameter(context_weights,"context-weights",string(""));
+
// main loop over set of input sentences
boost::shared_ptr<InputType> source;
@@ -228,6 +231,12 @@ batch_run()
task->SetContextString(*source->GetContext());
else task->SetContextString(context_string);
+ //if (source->GetContextWeights().isEmpty())
+ // task->SetContextWeights(*source->GetContextWeights());
+ /*else //The context_weights will never be passed to the config file.*/
+ if (context_weights != "") {
+ task->SetContextWeights(context_weights);
+ }
// Allow for (sentence-)context-specific processing prior to
// decoding. This can be used, for example, for context-sensitive
// phrase lookup.
diff --git a/moses/FF/StatefulFeatureFunction.h b/moses/FF/StatefulFeatureFunction.h
index c12f9516f..9baa4735d 100644
--- a/moses/FF/StatefulFeatureFunction.h
+++ b/moses/FF/StatefulFeatureFunction.h
@@ -37,6 +37,14 @@ public:
const FFState* prev_state,
ScoreComponentCollection* accumulator) const = 0;
+ virtual FFState* EvaluateWhenAppliedWithContext(
+ ttasksptr const& ttasks,
+ const Hypothesis& cur_hypo,
+ const FFState* prev_state,
+ ScoreComponentCollection* accumulator) const {
+ return EvaluateWhenApplied(cur_hypo, prev_state, accumulator);
+ }
+
virtual FFState* EvaluateWhenApplied(
const ChartHypothesis& /* cur_hypo */,
int /* featureID - used to index the state in the previous hypotheses */,
diff --git a/moses/Hypothesis.cpp b/moses/Hypothesis.cpp
index bc466664a..b722ae05f 100644
--- a/moses/Hypothesis.cpp
+++ b/moses/Hypothesis.cpp
@@ -230,9 +230,11 @@ EvaluateWhenApplied(StatefulFeatureFunction const& sfff,
{
const StaticData &staticData = StaticData::Instance();
if (! staticData.IsFeatureFunctionIgnored( sfff )) {
- m_ffStates[state_idx]
- = sfff.EvaluateWhenApplied
- (*this, m_prevHypo ? m_prevHypo->m_ffStates[state_idx] : NULL,
+ Manager& manager = this->GetManager(); //Get the manager and the ttask
+ ttasksptr const& ttask = manager.GetTtask();
+
+ m_ffStates[state_idx] = sfff.EvaluateWhenAppliedWithContext
+ (ttask, *this, m_prevHypo ? m_prevHypo->m_ffStates[state_idx] : NULL,
&m_currScoreBreakdown);
}
}
diff --git a/moses/LM/Base.cpp b/moses/LM/Base.cpp
index 76a6336c3..8b69626ac 100644
--- a/moses/LM/Base.cpp
+++ b/moses/LM/Base.cpp
@@ -78,7 +78,12 @@ void LanguageModel::EvaluateInIsolation(const Phrase &source
float fullScore, nGramScore;
size_t oovCount;
- CalcScore(targetPhrase, fullScore, nGramScore, oovCount);
+ if (targetPhrase.HasTtaskSPtr()){
+ CalcScoreWithContext(targetPhrase.GetTtask(), targetPhrase, fullScore, nGramScore, oovCount);
+ }else{
+ CalcScore(targetPhrase, fullScore, nGramScore, oovCount);
+ }
+ //CalcScore(targetPhrase, fullScore, nGramScore, oovCount);
float estimateScore = fullScore - nGramScore;
if (StaticData::Instance().GetLMEnableOOVFeature()) {
diff --git a/moses/LM/Base.h b/moses/LM/Base.h
index eb0a98ca1..cfe92c6ba 100644
--- a/moses/LM/Base.h
+++ b/moses/LM/Base.h
@@ -72,6 +72,9 @@ public:
* \param oovCount number of LM OOVs
*/
virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, std::size_t &oovCount) const = 0;
+ virtual void CalcScoreWithContext(ttasksptr const& ttask, const Phrase &phrase, float &fullScore, float &ngramScore, std::size_t &oovCount) const {
+ CalcScore(phrase, fullScore, ngramScore, oovCount);
+ }
virtual void CalcScoreFromCache(const Phrase &phrase, float &fullScore, float &ngramScore, std::size_t &oovCount) const {
}
diff --git a/moses/LM/IRST.cpp b/moses/LM/IRST.cpp
index 4e4d66571..9448339aa 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;
@@ -237,7 +238,7 @@ const FFState* LanguageModelIRST::EmptyHypothesisState(const InputType &/*input*
return ret.release();
}
-void LanguageModelIRST::CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const
+void LanguageModelIRST::CalcScoreWithContext(ttasksptr const& ttasks, const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const
{
fullScore = 0;
ngramScore = 0;
@@ -245,6 +246,9 @@ void LanguageModelIRST::CalcScore(const Phrase &phrase, float &fullScore, float
if ( !phrase.GetSize() ) return;
+ //get the context_weight map here
+ std::map<std::string, float> context_weight = ttasks->GetContextWeights();
+
int _min = min(m_lmtb_size - 1, (int) phrase.GetSize());
int codes[m_lmtb_size];
@@ -278,13 +282,16 @@ void LanguageModelIRST::CalcScore(const Phrase &phrase, float &fullScore, float
fullScore = ngramScore + before_boundary;
}
-FFState* LanguageModelIRST::EvaluateWhenApplied(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const
+FFState* LanguageModelIRST::EvaluateWhenAppliedWithContext(ttasksptr const& ttasks, const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const
{
if (!hypo.GetCurrTargetLength()) {
std::auto_ptr<IRSTLMState> ret(new IRSTLMState(ps));
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;
diff --git a/moses/LM/IRST.h b/moses/LM/IRST.h
index e10751663..7dedde7b0 100644
--- a/moses/LM/IRST.h
+++ b/moses/LM/IRST.h
@@ -93,9 +93,9 @@ public:
virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = NULL) const;
- virtual FFState *EvaluateWhenApplied(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const;
+ virtual FFState *EvaluateWhenAppliedWithContext(ttasksptr const& ttasks, const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const;
- virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const;
+ virtual void CalcScoreWithContext(ttasksptr const& ttasks, const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const;
/*
virtual FFState *EvaluateWhenApplied(const ChartHypothesis& cur_hypo, int featureID, ScoreComponentCollection *accumulator) const;
diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp
index cf8737e3b..4eaf419c4 100644
--- a/moses/Parameter.cpp
+++ b/moses/Parameter.cpp
@@ -243,6 +243,7 @@ Parameter::Parameter()
AddParam(misc_opts,"feature", "All the feature functions should be here");
AddParam(misc_opts,"context-string",
"A (tokenized) string containing context words for context-sensitive translation.");
+ AddParam(misc_opts,"context-weights", "A key-value map for context-sensitive translation.");
AddParam(misc_opts,"context-window",
"Context window (in words) for context-sensitive translation: {+|-|+-}<number>.");
diff --git a/moses/StaticData.cpp b/moses/StaticData.cpp
index 28d9f7831..83da42a9e 100644
--- a/moses/StaticData.cpp
+++ b/moses/StaticData.cpp
@@ -1115,7 +1115,9 @@ void StaticData::LoadSparseWeightsFromConfig()
}
std::map<std::string, std::vector<float> > weights = m_parameter->GetAllWeights();
- for (auto iter = weights.begin(); iter != weights.end(); ++iter) {
+ std::map<std::string, std::vector<float> >::iterator iter;
+// for (auto iter = weights.begin(); iter != weights.end(); ++iter) {
+ for (iter = weights.begin(); iter != weights.end(); ++iter) {
// this indicates that it is sparse feature
if (featureNames.find(iter->first) == featureNames.end()) {
UTIL_THROW_IF2(iter->second.size() != 1, "ERROR: only one weight per sparse feature allowed: " << iter->first);
diff --git a/moses/TargetPhrase.cpp b/moses/TargetPhrase.cpp
index 4976375e9..893edca08 100644
--- a/moses/TargetPhrase.cpp
+++ b/moses/TargetPhrase.cpp
@@ -32,6 +32,7 @@
#include "Util.h"
#include "AlignmentInfoCollection.h"
#include "InputPath.h"
+#include "TranslationTask.h"
#include "moses/TranslationModel/PhraseDictionary.h"
#include <boost/foreach.hpp>
@@ -47,6 +48,27 @@ TargetPhrase::TargetPhrase( std::string out_string, const PhraseDictionary *pt)
, m_alignNonTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
, m_lhsTarget(NULL)
, m_ruleSource(NULL)
+ , m_ttask_flag(false)
+ , m_container(pt)
+{
+ //ACAT
+ const StaticData &staticData = StaticData::Instance();
+ // XXX should this really be InputFactorOrder???
+ CreateFromString(Output, staticData.GetInputFactorOrder(), out_string,
+ // staticData.GetFactorDelimiter(), // eliminated [UG]
+ NULL);
+}
+
+TargetPhrase::TargetPhrase(ttasksptr& ttask, std::string out_string, const PhraseDictionary *pt)
+ :Phrase(0)
+ , m_fullScore(0.0)
+ , m_futureScore(0.0)
+ , m_alignTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
+ , m_alignNonTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
+ , m_lhsTarget(NULL)
+ , m_ruleSource(NULL)
+ , m_ttask(ttask)
+ , m_ttask_flag(true)
, m_container(pt)
{
@@ -58,6 +80,34 @@ TargetPhrase::TargetPhrase( std::string out_string, const PhraseDictionary *pt)
NULL);
}
+TargetPhrase::TargetPhrase(ttasksptr& ttask, const PhraseDictionary *pt)
+ :Phrase()
+ , m_fullScore(0.0)
+ , m_futureScore(0.0)
+ , m_alignTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
+ , m_alignNonTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
+ , m_lhsTarget(NULL)
+ , m_ruleSource(NULL)
+ , m_ttask(ttask)
+ , m_ttask_flag(true)
+ , m_container(pt)
+{
+}
+
+TargetPhrase::TargetPhrase(ttasksptr& ttask, const Phrase &phrase, const PhraseDictionary *pt)
+ : Phrase(phrase)
+ , m_fullScore(0.0)
+ , m_futureScore(0.0)
+ , m_alignTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
+ , m_alignNonTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
+ , m_lhsTarget(NULL)
+ , m_ruleSource(NULL)
+ , m_ttask(ttask)
+ , m_ttask_flag(true)
+ , m_container(pt)
+{
+}
+
TargetPhrase::TargetPhrase(const PhraseDictionary *pt)
:Phrase()
, m_fullScore(0.0)
@@ -66,6 +116,7 @@ TargetPhrase::TargetPhrase(const PhraseDictionary *pt)
, m_alignNonTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
, m_lhsTarget(NULL)
, m_ruleSource(NULL)
+ , m_ttask_flag(false)
, m_container(pt)
{
}
@@ -78,6 +129,7 @@ TargetPhrase::TargetPhrase(const Phrase &phrase, const PhraseDictionary *pt)
, m_alignNonTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
, m_lhsTarget(NULL)
, m_ruleSource(NULL)
+ , m_ttask_flag(false)
, m_container(pt)
{
}
@@ -91,6 +143,8 @@ TargetPhrase::TargetPhrase(const TargetPhrase &copy)
, m_alignTerm(copy.m_alignTerm)
, m_alignNonTerm(copy.m_alignNonTerm)
, m_properties(copy.m_properties)
+ , m_ttask(copy.m_ttask)
+ , m_ttask_flag(true)
, m_container(copy.m_container)
{
if (copy.m_lhsTarget) {
@@ -123,6 +177,14 @@ void TargetPhrase::WriteToRulePB(hgmert::Rule* pb) const
}
#endif
+bool TargetPhrase::HasTtaskSPtr() const {
+ return m_ttask_flag;
+}
+
+const ttasksptr& TargetPhrase::GetTtask() const {
+ return m_ttask;
+}
+
void TargetPhrase::EvaluateInIsolation(const Phrase &source)
{
const std::vector<FeatureFunction*> &ffs = FeatureFunction::GetFeatureFunctions();
diff --git a/moses/TargetPhrase.h b/moses/TargetPhrase.h
index 35b06c1c7..4e6b1278b 100644
--- a/moses/TargetPhrase.h
+++ b/moses/TargetPhrase.h
@@ -32,6 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "AlignmentInfoCollection.h"
#include "moses/PP/PhraseProperty.h"
#include "util/string_piece.hh"
+//#include "moses/TranslationTask.h"
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>
@@ -52,15 +53,16 @@ class PhraseDictionary;
class TargetPhrase: public Phrase
{
public:
- typedef std::map<FeatureFunction const*, boost::shared_ptr<Scores> >
- ScoreCache_t;
+ typedef std::map<FeatureFunction const*, boost::shared_ptr<Scores> > ScoreCache_t;
ScoreCache_t const& GetExtraScores() const;
Scores const* GetExtraScores(FeatureFunction const* ff) const;
- void SetExtraScores(FeatureFunction const* ff,
- boost::shared_ptr<Scores> const& scores);
+ void SetExtraScores(FeatureFunction const* ff,boost::shared_ptr<Scores> const& scores);
+
private:
ScoreCache_t m_cached_scores;
+ ttasksptr m_ttask;
+ bool m_ttask_flag;
private:
friend std::ostream& operator<<(std::ostream&, const TargetPhrase&);
@@ -85,6 +87,14 @@ public:
TargetPhrase(std::string out_string, const PhraseDictionary *pt = NULL);
TargetPhrase(const TargetPhrase &copy);
explicit TargetPhrase(const Phrase &targetPhrase, const PhraseDictionary *pt);
+
+ /*ttasksptr version*/
+ TargetPhrase(ttasksptr &ttask, const PhraseDictionary *pt = NULL);
+ TargetPhrase(ttasksptr &ttask, std::string out_string, const PhraseDictionary *pt = NULL);
+ explicit TargetPhrase(ttasksptr &ttask, const Phrase &targetPhrase, const PhraseDictionary *pt);
+ const ttasksptr& GetTtask() const;
+ bool HasTtaskSPtr() const;
+
~TargetPhrase();
// 1st evaluate method. Called during loading of phrase table.
diff --git a/moses/TranslationModel/UG/mm/ug_bitext.h b/moses/TranslationModel/UG/mm/ug_bitext.h
index 2d2afc3ca..fc433669c 100644
--- a/moses/TranslationModel/UG/mm/ug_bitext.h
+++ b/moses/TranslationModel/UG/mm/ug_bitext.h
@@ -192,6 +192,8 @@ namespace Moses {
sptr<DocumentBias>
SetupDocumentBias(string const& bserver, string const& text, ostream* log) const;
+ sptr<DocumentBias>
+ SetupDocumentBias(map<string,float> context_weights, ostream* log) const;
void
mark_match(Token const* start, Token const* end, iter const& m,
@@ -434,6 +436,20 @@ namespace Moses {
}
template<typename Token>
+ sptr<DocumentBias>
+ Bitext<Token>::
+ SetupDocumentBias
+ ( map<string,float> context_weights, ostream* log ) const
+ {
+ sptr<DocumentBias> ret;
+ UTIL_THROW_IF2(m_sid2docid == NULL,
+ "Document bias requested but no document map loaded.");
+ ret.reset(new DocumentBias(*m_sid2docid, m_docname2docid,
+ context_weights, log));
+ return ret;
+ }
+
+ template<typename Token>
void
Bitext<Token>::
prep(iter const& phrase) const
diff --git a/moses/TranslationModel/UG/mm/ug_sampling_bias.cc b/moses/TranslationModel/UG/mm/ug_sampling_bias.cc
index d54305997..f5e660456 100644
--- a/moses/TranslationModel/UG/mm/ug_sampling_bias.cc
+++ b/moses/TranslationModel/UG/mm/ug_sampling_bias.cc
@@ -108,6 +108,21 @@ namespace Moses
// #endif
}
+ DocumentBias
+ ::DocumentBias(std::vector<id_type> const& sid2doc,
+ std::map<std::string,id_type> const& docname2docid,
+ std::map<std::string, float> const& context_weights,
+ std::ostream* log)
+ : m_sid2docid(sid2doc)
+ , m_bias(docname2docid.size(), 0)
+ {
+ init(context_weights, docname2docid);
+ }
+
+ std::map<std::string, float>& SamplingBias::getBiasMap() {
+ return m_bias_map;
+ }
+
void
DocumentBias
::init_from_json
@@ -144,6 +159,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 24d39689e..999d93704 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<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
@@ -46,6 +48,11 @@ namespace Moses
std::string const& server_url, std::string const& text,
std::ostream* log);
+ DocumentBias(std::vector<id_type> const& sid2doc,
+ std::map<std::string,id_type> const& docname2docid,
+ std::map<std::string, float> const& context_weights,
+ std::ostream* log);
+
void
init_from_json
( std::string const& json,
diff --git a/moses/TranslationModel/UG/mmsapt.cpp b/moses/TranslationModel/UG/mmsapt.cpp
index f05c0d59b..7b212c8df 100644
--- a/moses/TranslationModel/UG/mmsapt.cpp
+++ b/moses/TranslationModel/UG/mmsapt.cpp
@@ -496,7 +496,8 @@ namespace Moses
TargetPhrase*
Mmsapt::
- mkTPhrase(Phrase const& src,
+ mkTPhrase(ttasksptr const& ttask,
+ Phrase const& src,
PhrasePair<Token>* fix,
PhrasePair<Token>* dyn,
sptr<Bitext<Token> > const& dynbt) const
@@ -547,7 +548,8 @@ namespace Moses
BOOST_FOREACH(sptr<pscorer> const& ff, m_active_ff_common)
(*ff)(*dynbt, pool, &fvals);
}
- TargetPhrase* tp = new TargetPhrase(this);
+
+ TargetPhrase* tp = new TargetPhrase(const_cast<ttasksptr&>(ttask), this);
Token const* x = fix ? fix->start2 : dyn->start2;
uint32_t len = fix ? fix->len2 : dyn->len2;
for (uint32_t k = 0; k < len; ++k, x = x->next())
@@ -687,12 +689,12 @@ namespace Moses
while (i < ppfix.size() && k < ppdyn.size())
{
int cmp = sorter.cmp(ppfix[i], ppdyn[k]);
- if (cmp < 0) ret->Add(mkTPhrase(src,&ppfix[i++],NULL,dyn));
- else if (cmp == 0) ret->Add(mkTPhrase(src,&ppfix[i++],&ppdyn[k++],dyn));
- else ret->Add(mkTPhrase(src,NULL,&ppdyn[k++],dyn));
+ if (cmp < 0) ret->Add(mkTPhrase(ttask,src,&ppfix[i++],NULL,dyn));
+ else if (cmp == 0) ret->Add(mkTPhrase(ttask,src,&ppfix[i++],&ppdyn[k++],dyn));
+ else ret->Add(mkTPhrase(ttask,src,NULL,&ppdyn[k++],dyn));
}
- while (i < ppfix.size()) ret->Add(mkTPhrase(src,&ppfix[i++],NULL,dyn));
- while (k < ppdyn.size()) ret->Add(mkTPhrase(src,NULL,&ppdyn[k++],dyn));
+ while (i < ppfix.size()) ret->Add(mkTPhrase(ttask,src,&ppfix[i++],NULL,dyn));
+ while (k < ppdyn.size()) ret->Add(mkTPhrase(ttask,src,NULL,&ppdyn[k++],dyn));
if (m_tableLimit) ret->Prune(true, m_tableLimit);
else ret->Prune(true,ret->GetSize());
@@ -791,9 +793,25 @@ 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);
+ } else if (!ttask->GetContextWeights().empty()) {
+ if (m_bias_log)
+ {
+ *m_bias_log << HERE << endl
+ << "BIAS FROM MAP LOOKUP" << endl;
+ context->bias_log = m_bias_log;
+ }
+ context->bias
+ = btfix.SetupDocumentBias(ttask->GetContextWeights(), m_bias_log);
+ context->bias->loglevel = m_bias_loglevel;
+ context->bias->log = m_bias_log;
+ if (!context->cache1) context->cache1.reset(new pstats::cache_t);
+ if (!context->cache2) context->cache2.reset(new pstats::cache_t);
}
boost::unique_lock<boost::shared_mutex> mylock(m_lock);
sptr<TPCollCache> localcache = scope->get<TPCollCache>(cache_key);
diff --git a/moses/TranslationModel/UG/mmsapt.h b/moses/TranslationModel/UG/mmsapt.h
index 5f688cfd8..81687cc50 100644
--- a/moses/TranslationModel/UG/mmsapt.h
+++ b/moses/TranslationModel/UG/mmsapt.h
@@ -149,7 +149,8 @@ namespace Moses
mm2dtable_t COOCraw;
TargetPhrase*
- mkTPhrase(Phrase const& src,
+ mkTPhrase(ttasksptr const& ttask,
+ Phrase const& src,
Moses::bitext::PhrasePair<Token>* fix,
Moses::bitext::PhrasePair<Token>* dyn,
sptr<Bitext<Token> > const& dynbt) const;
diff --git a/moses/TranslationTask.cpp b/moses/TranslationTask.cpp
index 61cdfc162..0c6e6c69e 100644
--- a/moses/TranslationTask.cpp
+++ b/moses/TranslationTask.cpp
@@ -30,6 +30,19 @@ TranslationTask
return m_context_string;
}
+std::map<std::string, float> const&
+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)
@@ -37,6 +50,16 @@ TranslationTask
m_context_string = context;
}
+void
+TranslationTask
+::SetContextWeights(std::string const& context_weights)
+{
+ std::vector<std::string> tokens = Tokenize(context_weights,":");
+ for (std::vector<std::string>::iterator it = tokens.begin(); it != tokens.end(); it++) {
+ std::vector<std::string> key_and_value = Tokenize(*it, ",");
+ m_context_weights.insert(std::pair<std::string, float>(key_and_value[0], atof(key_and_value[1].c_str())));
+ }
+}
boost::shared_ptr<TranslationTask>
diff --git a/moses/TranslationTask.h b/moses/TranslationTask.h
index 2b75c47d5..f37bad535 100644
--- a/moses/TranslationTask.h
+++ b/moses/TranslationTask.h
@@ -67,6 +67,7 @@ protected:
// task stays alive till it's done with it.
std::string m_context_string;
+ std::map<std::string, float> m_context_weights;
public:
boost::shared_ptr<TranslationTask>
@@ -115,6 +116,11 @@ public:
std::string const& GetContextString() const;
void SetContextString(std::string const& context);
+ 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;
boost::shared_ptr<Moses::IOWrapper> m_ioWrapper;