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
path: root/moses
diff options
context:
space:
mode:
authorMatthias Huck <huck@i6.informatik.rwth-aachen.de>2015-02-09 16:52:05 +0300
committerMatthias Huck <huck@i6.informatik.rwth-aachen.de>2015-02-09 16:52:05 +0300
commit53ce063214d9c942847ddf7b2b7e3b43f2f882b6 (patch)
treee60928d34625b259fd8e3582b664d8a4d1c93373 /moses
parentce80e53b30f766ab85cb58c4a2d06742b4a4f38b (diff)
tuneable-components config parameter for feature functions
Diffstat (limited to 'moses')
-rw-r--r--moses/FF/FeatureFunction.cpp31
-rw-r--r--moses/FF/FeatureFunction.h14
-rw-r--r--moses/Parameter.cpp22
-rw-r--r--moses/ScoreComponentCollection.cpp6
-rw-r--r--moses/Util.cpp6
5 files changed, 71 insertions, 8 deletions
diff --git a/moses/FF/FeatureFunction.cpp b/moses/FF/FeatureFunction.cpp
index 71f4ff568..fa898857d 100644
--- a/moses/FF/FeatureFunction.cpp
+++ b/moses/FF/FeatureFunction.cpp
@@ -50,6 +50,7 @@ FeatureFunction(const std::string& line)
, m_verbosity(std::numeric_limits<std::size_t>::max())
, m_numScoreComponents(1)
{
+ m_numTuneableComponents = m_numScoreComponents;
Initialize(line);
}
@@ -61,6 +62,7 @@ FeatureFunction(size_t numScoreComponents,
, m_verbosity(std::numeric_limits<std::size_t>::max())
, m_numScoreComponents(numScoreComponents)
{
+ m_numTuneableComponents = m_numScoreComponents;
Initialize(line);
}
@@ -95,6 +97,7 @@ void FeatureFunction::ParseLine(const std::string &line)
if (args[0] == "num-features") {
m_numScoreComponents = Scan<size_t>(args[1]);
+ m_numTuneableComponents = m_numScoreComponents;
} else if (args[0] == "name") {
m_description = args[1];
} else {
@@ -120,13 +123,17 @@ void FeatureFunction::SetParameter(const std::string& key, const std::string& va
{
if (key == "tuneable") {
m_tuneable = Scan<bool>(value);
+ } else if (key == "tuneable-components") {
+ UTIL_THROW_IF2(!m_tuneable, GetScoreProducerDescription()
+ << ": tuneable-components cannot be set if tuneable=false");
+ SetTuneableComponents(value);
} else if (key == "require-sorting-after-source-context") {
m_requireSortingAfterSourceContext = Scan<bool>(value);
} else if (key == "verbosity") {
m_verbosity = Scan<size_t>(value);
} else if (key == "filterable") { //ignore
} else {
- UTIL_THROW(util::Exception, "Unknown argument " << key << "=" << value);
+ UTIL_THROW2(GetScoreProducerDescription() << ": Unknown argument " << key << "=" << value);
}
}
@@ -142,7 +149,27 @@ void FeatureFunction::ReadParameters()
std::vector<float> FeatureFunction::DefaultWeights() const
{
- UTIL_THROW(util::Exception, "No default weights");
+ UTIL_THROW2(GetScoreProducerDescription() << ": No default weights");
+}
+
+void FeatureFunction::SetTuneableComponents(const std::string& value)
+{
+ std::vector<std::string> toks = Tokenize(value,",");
+ UTIL_THROW_IF2(toks.empty(), GetScoreProducerDescription()
+ << ": Empty tuneable-components");
+ UTIL_THROW_IF2(toks.size()!=m_numScoreComponents, GetScoreProducerDescription()
+ << ": tuneable-components value has to be a comma-separated list of "
+ << m_numScoreComponents << " boolean values");
+
+ m_tuneableComponents.resize(m_numScoreComponents);
+ m_numTuneableComponents = m_numScoreComponents;
+
+ for (size_t i = 0; i < toks.size(); ++i) {
+ m_tuneableComponents[i] = Scan<bool>(toks[i]);
+ if (!m_tuneableComponents[i]) {
+ --m_numTuneableComponents;
+ }
+ }
}
}
diff --git a/moses/FF/FeatureFunction.h b/moses/FF/FeatureFunction.h
index 767270140..b59998d9d 100644
--- a/moses/FF/FeatureFunction.h
+++ b/moses/FF/FeatureFunction.h
@@ -39,6 +39,8 @@ protected:
bool m_requireSortingAfterSourceContext;
size_t m_verbosity;
size_t m_numScoreComponents;
+ std::vector<bool> m_tuneableComponents;
+ size_t m_numTuneableComponents;
//In case there's multiple producers with the same description
static std::multiset<std::string> description_counts;
@@ -90,6 +92,17 @@ public:
return m_tuneable;
}
+ virtual bool HasTuneableComponents() const {
+ return m_numTuneableComponents;
+ }
+
+ virtual bool IsTuneableComponent(size_t i) const {
+ if (m_numTuneableComponents == m_numScoreComponents) {
+ return true;
+ }
+ return m_tuneableComponents[i];
+ }
+
virtual bool RequireSortingAfterSourceContext() const {
return m_requireSortingAfterSourceContext;
}
@@ -151,6 +164,7 @@ public:
virtual void SetParameter(const std::string& key, const std::string& value);
virtual void ReadParameters();
+ virtual void SetTuneableComponents(const std::string& value);
};
}
diff --git a/moses/Parameter.cpp b/moses/Parameter.cpp
index c5677b73b..0289eebff 100644
--- a/moses/Parameter.cpp
+++ b/moses/Parameter.cpp
@@ -970,11 +970,13 @@ void Parameter::WeightOverwrite()
// should only be on 1 line
UTIL_THROW_IF2(vec.size() != 1,
- "Weight override should only be on 1 line");
+ "weight-overwrite should only be on 1 line");
string name("");
vector<float> weights;
vector<string> toks = Tokenize(vec[0]);
+ size_t cnt = 0;
+ const std::vector<float>* oldWeights = NULL;
for (size_t i = 0; i < toks.size(); ++i) {
const string &tok = toks[i];
@@ -988,10 +990,24 @@ void Parameter::WeightOverwrite()
}
name = tok.substr(0, tok.size() - 1);
+ std::map<std::string, std::vector<float> >::const_iterator found = m_weights.find(name);
+ if (found!=m_weights.end()) {
+ oldWeights = &(found->second);
+ } else {
+ oldWeights = NULL;
+ }
+ cnt = 0;
} else {
// a weight for curr ff
- float weight = Scan<float>(toks[i]);
- weights.push_back(weight);
+ if (toks[i] == "x") {
+ UTIL_THROW_IF2(!oldWeights || cnt>=oldWeights->size(),
+ "Keeping previous weight failed in weight-overwrite");
+ weights.push_back(oldWeights->at(cnt));
+ } else {
+ float weight = Scan<float>(toks[i]);
+ weights.push_back(weight);
+ }
+ ++cnt;
}
}
diff --git a/moses/ScoreComponentCollection.cpp b/moses/ScoreComponentCollection.cpp
index a1c864692..e656743ec 100644
--- a/moses/ScoreComponentCollection.cpp
+++ b/moses/ScoreComponentCollection.cpp
@@ -332,14 +332,16 @@ void ScoreComponentCollection::OutputFeatureScores( std::ostream& out
bool labeledOutput = staticData.IsLabeledNBestList();
// regular features (not sparse)
- if (ff->GetNumScoreComponents() != 0) {
+ if (ff->HasTuneableComponents()) {
if( labeledOutput && lastName != ff->GetScoreProducerDescription() ) {
lastName = ff->GetScoreProducerDescription();
out << " " << lastName << "=";
}
vector<float> scores = GetScoresForProducer( ff );
for (size_t j = 0; j<scores.size(); ++j) {
- out << " " << scores[j];
+ if (ff->IsTuneableComponent(j)) {
+ out << " " << scores[j];
+ }
}
}
diff --git a/moses/Util.cpp b/moses/Util.cpp
index 5b6f16e2b..1d1df7d58 100644
--- a/moses/Util.cpp
+++ b/moses/Util.cpp
@@ -348,7 +348,11 @@ void PrintFeatureWeight(const FeatureFunction* ff)
size_t numScoreComps = ff->GetNumScoreComponents();
vector<float> values = StaticData::Instance().GetAllWeights().GetScoresForProducer(ff);
for (size_t i = 0; i < numScoreComps; ++i) {
- cout << " " << values[i];
+ if (ff->IsTuneableComponent(i)) {
+ cout << " " << values[i];
+ } else {
+ cout << " UNTUNEABLECOMPONENT";
+ }
}
cout << endl;