Hiero phrase orientation: modify some parameters

This commit is contained in:
Matthias Huck 2015-12-18 17:24:42 +00:00
parent 5a10cbdf59
commit 0a39efb6c8
3 changed files with 24 additions and 17 deletions

View File

@ -82,8 +82,8 @@ const std::string PhraseOrientationFeature::DORIENT("D");
PhraseOrientationFeature::PhraseOrientationFeature(const std::string &line)
: StatefulFeatureFunction(6, line)
, m_glueTargetLHSStr("Q")
, m_distinguishStates(true)
, m_glueLabelStr("Q")
, m_distinguishStates(false)
, m_useSparseWord(false)
, m_useSparseNT(false)
, m_offsetR2LScores(m_numScoreComponents/2)
@ -93,24 +93,24 @@ PhraseOrientationFeature::PhraseOrientationFeature(const std::string &line)
VERBOSE(1, "Initializing feature " << GetScoreProducerDescription() << " ...");
ReadParameters();
FactorCollection &factorCollection = FactorCollection::Instance();
m_glueTargetLHS = factorCollection.AddFactor(m_glueTargetLHSStr, true);
m_glueLabel = factorCollection.AddFactor(m_glueLabelStr, true);
VERBOSE(1, " Done." << std::endl);
}
void PhraseOrientationFeature::SetParameter(const std::string& key, const std::string& value)
{
if (key == "glueTargetLHS") {
m_glueTargetLHSStr = value;
} else if (key == "distinguishStates") {
if (key == "glue-label") {
m_glueLabelStr = value;
} else if (key == "distinguish-states") {
m_distinguishStates = Scan<bool>(value);
} else if (key == "sparseWord") {
} else if (key == "sparse-word") {
m_useSparseWord = Scan<bool>(value);
} else if (key == "sparseNT") {
} else if (key == "sparse-nt") {
m_useSparseNT = Scan<bool>(value);
} else if (key == "targetWordList") {
} else if (key == "target-word-list") {
m_filenameTargetWordList = value;
} else if (key == "sourceWordList") {
} else if (key == "source-word-list") {
m_filenameSourceWordList = value;
} else {
StatefulFeatureFunction::SetParameter(key, value);
@ -206,7 +206,7 @@ void PhraseOrientationFeature::EvaluateInIsolation(const Phrase &source,
MosesTraining::PhraseOrientation::REO_CLASS l2rOrientation = phraseOrientation.GetOrientationInfo(sourceIndex,sourceIndex,MosesTraining::PhraseOrientation::REO_DIR_L2R);
if ( ((targetIndex == 0) || !phraseOrientation.TargetSpanIsAligned(0,targetIndex)) // boundary non-terminal in rule-initial position (left boundary)
&& (targetPhraseLHS != m_glueTargetLHS) ) { // and not glue rule
&& (targetPhraseLHS != m_glueLabel) ) { // and not glue rule
FEATUREVERBOSE(3, "Left boundary: targetIndex== " << targetIndex);
if (targetIndex != 0) {
@ -236,7 +236,7 @@ void PhraseOrientationFeature::EvaluateInIsolation(const Phrase &source,
MosesTraining::PhraseOrientation::REO_CLASS r2lOrientation = phraseOrientation.GetOrientationInfo(sourceIndex,sourceIndex,MosesTraining::PhraseOrientation::REO_DIR_R2L);
if ( ((targetIndex == targetPhrase.GetSize()-1) || !phraseOrientation.TargetSpanIsAligned(targetIndex,targetPhrase.GetSize()-1)) // boundary non-terminal in rule-final position (right boundary)
&& (targetPhraseLHS != m_glueTargetLHS) ) { // and not glue rule
&& (targetPhraseLHS != m_glueLabel) ) { // and not glue rule
FEATUREVERBOSE(3, "Right boundary: targetIndex== " << targetIndex);
if (targetIndex != targetPhrase.GetSize()-1) {
@ -891,7 +891,7 @@ void PhraseOrientationFeature::SparseNonTerminalL2RScore(const Factor* nonTermin
ScoreComponentCollection* scoreBreakdown,
const std::string* o) const
{
if ( nonTerminalSymbol != m_glueTargetLHS ) {
if ( nonTerminalSymbol != m_glueLabel ) {
const std::string& nonTerminalString = nonTerminalSymbol->GetString().as_string();
scoreBreakdown->PlusEquals(this,
"L2R"+*o+"_n_"+nonTerminalString,
@ -905,7 +905,7 @@ void PhraseOrientationFeature::SparseNonTerminalR2LScore(const Factor* nonTermin
ScoreComponentCollection* scoreBreakdown,
const std::string* o) const
{
if ( nonTerminalSymbol != m_glueTargetLHS ) {
if ( nonTerminalSymbol != m_glueLabel ) {
const std::string& nonTerminalString = nonTerminalSymbol->GetString().as_string();
scoreBreakdown->PlusEquals(this,
"R2L"+*o+"_n_"+nonTerminalString,

View File

@ -405,8 +405,8 @@ protected:
static const std::string SORIENT;
static const std::string DORIENT;
std::string m_glueTargetLHSStr;
const Factor* m_glueTargetLHS;
std::string m_glueLabelStr;
const Factor* m_glueLabel;
bool m_distinguishStates;
bool m_useSparseWord;
bool m_useSparseNT;

View File

@ -2367,7 +2367,14 @@ sub create_ini {
print INI "PhrasePenalty\n";
print INI "SoftMatchingFeature name=SM0 path=$_UNKNOWN_WORD_SOFT_MATCHES_FILE\n" if $_TARGET_SYNTAX && defined($_UNKNOWN_WORD_SOFT_MATCHES_FILE);
print INI "SoftSourceSyntacticConstraintsFeature sourceLabelSetFile=$_GHKM_SOURCE_LABELS_FILE\n" if $_GHKM_SOURCE_LABELS && defined($_GHKM_SOURCE_LABELS_FILE);
print INI "PhraseOrientationFeature\n" if $_PHRASE_ORIENTATION;
if ($_PHRASE_ORIENTATION) {
print INI "PhraseOrientationFeature";
# find the label of the left-hand side non-terminal in glue rules (target non-terminal set)
my $TOPLABEL = `head -n 1 $___GLUE_GRAMMAR_FILE`;
$TOPLABEL =~ s/.* \|\|\| .* \[(.*)\] \|\|\| .*/\1/;
chomp($TOPLABEL);
print INI " glue-label=$TOPLABEL\n";
}
print INI $feature_spec;
print INI "\n# dense weights for feature functions\n";