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:
authorccorbett <ccorbett@1f5c12ca-751b-0410-a591-d2e778427230>2006-08-17 00:56:12 +0400
committerccorbett <ccorbett@1f5c12ca-751b-0410-a591-d2e778427230>2006-08-17 00:56:12 +0400
commitcdde0a6e11a65e15c9067de3af9fd3193a13097c (patch)
treea983eae67d55f2bbde4169f7ee9778f9226e0305 /moses
parent9c7ffb1fbb649eb086a5107911a423e6d57e2156 (diff)
final format of lexicalize reordering ini file
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@773 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'moses')
-rwxr-xr-xmoses/src/StaticData.cpp110
1 files changed, 63 insertions, 47 deletions
diff --git a/moses/src/StaticData.cpp b/moses/src/StaticData.cpp
index e2e51bc1f..b0fcabe98 100755
--- a/moses/src/StaticData.cpp
+++ b/moses/src/StaticData.cpp
@@ -188,6 +188,59 @@ bool StaticData::LoadParameters(int argc, char* argv[])
m_parameter.GetParam("distortion-file");
for(unsigned int i=0; i< lrFileVector.size(); i++ ) //loops for each distortion model
{
+
+ //if this went wrong, something went wrong in the parsing.
+ const vector<string> &lrTypeVector = m_parameter.GetParam("distortion");
+ //defaults, but at least one of these per model should be explicitly specified in the .ini file
+ int orientation = DistortionOrientationType::Msd,
+ direction = LexReorderType::Bidirectional,
+ condition = LexReorderType::Fe;
+
+ if(lrTypeVector.size() < i)
+ {
+ std::cerr<<"ERROR: please specify one line of configuration under [distortion] per distortion model in the moses configuration file\n";
+ abort();
+ }
+
+ //Loop through, overriding defaults with specifications
+ vector<string> parameters = Tokenize<string>(lrTypeVector[i],"-");
+ for (size_t param=0; param<parameters.size(); param++)
+ {
+ string val = parameters[param];
+ boost::algorithm::to_lower(val);
+ //orientation
+ if(val == "monotone")
+ orientation = DistortionOrientationType::Monotone;
+ else if(val == "msd")
+ orientation = DistortionOrientationType::Msd;
+ //direction
+ else if(val == "forward")
+ direction = LexReorderType::Forward;
+ else if(val == "backward")
+ direction = LexReorderType::Backward;
+ else if(val == "bidirectional")
+ direction = LexReorderType::Bidirectional;
+ //condition
+ else if(val == "f")
+ condition = LexReorderType::F;
+ else if(val == "fe")
+ condition = LexReorderType::Fe;
+ }
+ //compute the number of weights that ought to be in the table from this
+ size_t numWeightsInTable = 0;
+ if(orientation == DistortionOrientationType::Monotone)
+ {
+ numWeightsInTable = 2;
+ }
+ else
+ {
+ numWeightsInTable = 3;
+ }
+ if(direction == LexReorderType::Bidirectional)
+ {
+ numWeightsInTable *= 2;
+ }
+
vector<string> token = Tokenize(lrFileVector[i]);
//characteristics of the phrase table
vector<string> inputfactors = Tokenize(token[0],"-");
@@ -202,18 +255,16 @@ bool StaticData::LoadParameters(int argc, char* argv[])
input.push_back(0); // default, just in case the user is actually using a bidirectional model
output = Tokenize<FactorType>(inputfactors[0],",");
}
- size_t mertOneWeight = Scan<size_t>(token[1]);
- size_t numberWeights = Scan<size_t>(token[2]);
- std::string filePath= token[3];
-
- std::vector<float> m_lexWeights; //get the weights for this particular distortion reorderer
- std::vector<float> newLexWeights; //will remove the weights used by this distortion reorder, leaving the weights yet to be used
- if(mertOneWeight == 1) // this is useful if the user just wants to train one weight for the model
+ size_t numWeights = Scan<size_t>(token[1]);
+ std::string filePath= token[2];
+ std::vector<float> m_lexWeights; //will store the weights for this particular distortion reorderer
+ std::vector<float> newLexWeights; //we'll remove the weights used by this distortion reorder, leaving the weights yet to be used
+ if(numWeights == 1) // this is useful if the user just wants to train one weight for the model
{
//add appropriate weight to weight vector
assert(distortionModelWeights.size()> 0); //if this fails the user has not specified enough weights
float wgt = distortionModelWeights[0];
- for(size_t i=0; i<numberWeights; i++)
+ for(size_t i=0; i<numWeightsInTable; i++)
{
m_lexWeights.push_back(wgt);
}
@@ -228,67 +279,32 @@ bool StaticData::LoadParameters(int argc, char* argv[])
else
{
//add appropriate weights to weight vector
- for(size_t i=0; i< numberWeights; i++)
+ for(size_t i=0; i< numWeightsInTable; i++)
{
assert(i < distortionModelWeights.size()); //if this fails the user has not specified enough weights
m_lexWeights.push_back(distortionModelWeights[i]);
}
//update the distortionModelWeight vector to remove these weights
- for(size_t i=numberWeights; i<distortionModelWeights.size(); i++)
+ for(size_t i=numWeightsInTable; i<distortionModelWeights.size(); i++)
{
newLexWeights.push_back(distortionModelWeights[i]);
}
distortionModelWeights = newLexWeights;
}
+ assert(m_lexWeights.size() == numWeightsInTable); //the end result should be a weight vector of the same size as the user configured model
TRACE_ERR("distortion-weights: ");
for(size_t weight=0; weight<m_lexWeights.size(); weight++)
{
TRACE_ERR(m_lexWeights[weight] << "\t");
}
TRACE_ERR(endl);
- //if this went wrong, something went wrong in the parsing.
- const vector<string> &lrTypeVector = m_parameter.GetParam("distortion");
- //defaults, but at least one of these per model should be explicitly specified in the .ini file
- int orientation = DistortionOrientationType::Msd,
- direction = LexReorderType::Bidirectional,
- condition = LexReorderType::Fe;
-
- if(lrTypeVector.size() < i)
- {
- std::cerr<<"ERROR: please specify one line of configuration under [distortion] per distortion model in the moses configuration file\n";
- abort();
- }
-
- //Loop through, overriding defaults with specifications
- vector<string> parameters = Tokenize<string>(lrTypeVector[i],"-");
- for (size_t param=0; param<parameters.size(); param++)
- {
- string val = parameters[param];
- boost::algorithm::to_lower(val);
- //orientation
- if(val == "monotone")
- orientation = DistortionOrientationType::Monotone;
- else if(val == "msd")
- orientation = DistortionOrientationType::Msd;
- //direction
- else if(val == "forward")
- direction = LexReorderType::Forward;
- else if(val == "backward")
- direction = LexReorderType::Backward;
- else if(val == "bidirectional")
- direction = LexReorderType::Bidirectional;
- //condition
- else if(val == "f")
- condition = LexReorderType::F;
- else if(val == "fe")
- condition = LexReorderType::Fe;
- }
timer.check("Starting to load lexical reorder table...");
TRACE_ERR(filePath << "...");
m_reorderModels.push_back(new LexicalReordering(filePath, orientation, direction, condition, m_lexWeights, input, output));
timer.check("Finished loading lexical reorder table.");
}
+
if (m_parameter.GetParam("lmodel-file").size() > 0)
{
// weights