Revert "Merge branch 'master' of ../mosesdecoder.export.bundle"

This reverts commit a106d27bf7, reversing
changes made to 7c93c47548.
This commit is contained in:
Lane Schwartz 2014-06-14 10:08:48 -04:00
parent a106d27bf7
commit 2b0f3f11c1
2 changed files with 24 additions and 68 deletions

View File

@ -65,6 +65,7 @@ StaticData::StaticData()
,m_factorDelimiter("|") // default delimiter between factors
,m_lmEnableOOVFeature(false)
,m_isAlwaysCreateDirectTranslationOption(false)
,m_currentWeightSetting("default")
,m_treeStructure(NULL)
{
m_xmlBrackets.first="<";
@ -560,7 +561,7 @@ bool StaticData::LoadData(Parameter *parameter)
UserMessage::Add("Unable to load weights from " + extraWeightConfig[0]);
return false;
}
AccessAllWeights().PlusEquals(extraWeights);
m_allWeights.PlusEquals(extraWeights);
}
//Load sparse features from config (overrules weight file)
@ -596,14 +597,14 @@ void StaticData::SetBooleanParameter( bool *parameter, string parameterName, boo
void StaticData::SetWeight(const FeatureFunction* sp, float weight)
{
AccessAllWeights().Resize();
AccessAllWeights().Assign(sp,weight);
m_allWeights.Resize();
m_allWeights.Assign(sp,weight);
}
void StaticData::SetWeights(const FeatureFunction* sp, const std::vector<float>& weights)
{
AccessAllWeights().Resize();
AccessAllWeights().Assign(sp,weights);
m_allWeights.Resize();
m_allWeights.Assign(sp,weights);
}
void StaticData::LoadNonTerminals()
@ -1006,7 +1007,7 @@ void StaticData::LoadSparseWeightsFromConfig() {
// 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);
AccessAllWeights().Assign(iter->first, iter->second[0]);
m_allWeights.Assign(iter->first, iter->second[0]);
}
}
@ -1031,7 +1032,7 @@ bool StaticData::LoadAlternateWeightSettings()
}
// copy main weight setting as default
m_weightSetting["default"] = new ScoreComponentCollection( AccessAllWeights() );
m_weightSetting["default"] = new ScoreComponentCollection( m_allWeights );
// go through specification in config file
string currentId = "";
@ -1194,7 +1195,7 @@ void StaticData::CheckLEGACYPT()
void StaticData::ResetWeights(const std::string &denseWeights, const std::string &sparseFile)
{
SetAllWeights(ScoreComponentCollection());
m_allWeights = ScoreComponentCollection();
// dense weights
string name("");
@ -1209,7 +1210,7 @@ void StaticData::ResetWeights(const std::string &denseWeights, const std::string
if (name != "") {
// save previous ff
const FeatureFunction &ff = FeatureFunction::FindFeatureFunction(name);
AccessAllWeights().Assign(&ff, weights);
m_allWeights.Assign(&ff, weights);
weights.clear();
}
@ -1222,7 +1223,7 @@ void StaticData::ResetWeights(const std::string &denseWeights, const std::string
}
const FeatureFunction &ff = FeatureFunction::FindFeatureFunction(name);
AccessAllWeights().Assign(&ff, weights);
m_allWeights.Assign(&ff, weights);
// sparse weights
InputFileStream sparseStrme(sparseFile);
@ -1235,7 +1236,7 @@ void StaticData::ResetWeights(const std::string &denseWeights, const std::string
UTIL_THROW_IF2(names.size() != 2, "Incorrect sparse weight name. Should be FFName_spareseName");
const FeatureFunction &ff = FeatureFunction::FindFeatureFunction(names[0]);
AccessAllWeights().Assign(&ff, names[1], Scan<float>(toks[1]));
m_allWeights.Assign(&ff, names[1], Scan<float>(toks[1]));
}
}

View File

@ -36,7 +36,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#ifdef WITH_THREADS
#include <boost/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/tss.hpp>
#endif
#include "Parameter.h"
@ -65,46 +64,10 @@ class StaticData
private:
static StaticData s_instance;
ScoreComponentCollection& AccessAllWeights() const {
#ifdef WITH_THREADS
return *(m_allWeights.get());
#else
return m_allWeights;
#endif
}
std::string& AccessCurrentWeightSetting() const {
#ifdef WITH_THREADS
std::string * pointer = m_currentWeightSetting.get();
if (pointer == NULL) {
SetCurrentWeightSetting("default");
return *(m_currentWeightSetting.get());
} else {
return *pointer;
}
#else
return m_currentWeightSetting;
#endif
}
void SetCurrentWeightSetting(std::string weightSetting) const {
#ifdef WITH_THREADS
m_currentWeightSetting.reset(new std::string(weightSetting));
#else
m_currentWeightSetting = weightSetting;
#endif
}
protected:
Parameter *m_parameter;
std::vector<FactorType> m_inputFactorOrder, m_outputFactorOrder;
#ifdef WITH_THREADS
mutable boost::thread_specific_ptr< ScoreComponentCollection > m_allWeights;
#else
mutable ScoreComponentCollection m_allWeights;
#endif
mutable ScoreComponentCollection m_allWeights;
std::vector<DecodeGraph*> m_decodeGraphs;
@ -228,11 +191,7 @@ protected:
long m_startTranslationId;
// alternate weight settings
#ifdef WITH_THREADS
mutable boost::thread_specific_ptr< std::string > m_currentWeightSetting;
#else
mutable std::string m_currentWeightSetting;
#endif
std::map< std::string, ScoreComponentCollection* > m_weightSetting; // core weights
std::map< std::string, std::set< std::string > > m_weightSettingIgnoreFF; // feature function
std::map< std::string, std::set< size_t > > m_weightSettingIgnoreDP; // decoding path
@ -468,20 +427,16 @@ public:
}
const ScoreComponentCollection& GetAllWeights() const {
return AccessAllWeights();
return m_allWeights;
}
void SetAllWeights(const ScoreComponentCollection& weights) {
#ifdef WITH_THREADS
m_allWeights.reset(new ScoreComponentCollection(weights));
#else
m_allWeights = weights;
#endif
}
//Weight for a single-valued feature
float GetWeight(const FeatureFunction* sp) const {
return AccessAllWeights().GetScoreForProducer(sp);
return m_allWeights.GetScoreForProducer(sp);
}
//Weight for a single-valued feature
@ -490,11 +445,11 @@ public:
//Weights for feature with fixed number of values
std::vector<float> GetWeights(const FeatureFunction* sp) const {
return AccessAllWeights().GetScoresForProducer(sp);
return m_allWeights.GetScoresForProducer(sp);
}
float GetSparseWeight(const FName& featureName) const {
return AccessAllWeights().GetSparseWeight(featureName);
return m_allWeights.GetSparseWeight(featureName);
}
//Weights for feature with fixed number of values
@ -694,7 +649,7 @@ public:
return false;
}
std::map< std::string, std::set< std::string > >::const_iterator lookupIgnoreFF
= m_weightSettingIgnoreFF.find( AccessCurrentWeightSetting() );
= m_weightSettingIgnoreFF.find( m_currentWeightSetting );
if (lookupIgnoreFF == m_weightSettingIgnoreFF.end()) {
return false;
}
@ -712,7 +667,7 @@ public:
return false;
}
std::map< std::string, std::set< size_t > >::const_iterator lookupIgnoreDP
= m_weightSettingIgnoreDP.find( AccessCurrentWeightSetting() );
= m_weightSettingIgnoreDP.find( m_currentWeightSetting );
if (lookupIgnoreDP == m_weightSettingIgnoreDP.end()) {
return false;
}
@ -725,7 +680,7 @@ public:
void SetWeightSetting(const std::string &settingName) const {
// if no change in weight setting, do nothing
if (AccessCurrentWeightSetting() == settingName) {
if (m_currentWeightSetting == settingName) {
return;
}
@ -736,7 +691,7 @@ public:
}
// find the setting
SetCurrentWeightSetting(settingName);
m_currentWeightSetting = settingName;
std::map< std::string, ScoreComponentCollection* >::const_iterator i =
m_weightSetting.find( settingName );
@ -747,11 +702,11 @@ public:
<< " does not exist in model, using default weight setting instead";
UserMessage::Add(strme.str());
i = m_weightSetting.find( "default" );
SetCurrentWeightSetting("default");
m_currentWeightSetting = "default";
}
// set weights
AccessAllWeights() = *(i->second);
m_allWeights = *(i->second);
}
float GetWeightWordPenalty() const;