diff options
author | Ales Tamchyna <tamchyna@ufal.mff.cuni.cz> | 2016-03-24 20:09:07 +0300 |
---|---|---|
committer | Ales Tamchyna <tamchyna@ufal.mff.cuni.cz> | 2016-03-24 20:09:07 +0300 |
commit | 4f85b605c901114cce082fde55efca6541efcfd1 (patch) | |
tree | 4c3a493673ff6bf19afa402fd7b74ce6b7d73e47 /moses/FF | |
parent | 25363528759959d9eb19a3bfff184de8a90e3817 (diff) |
bilingual features for VW
Diffstat (limited to 'moses/FF')
-rw-r--r-- | moses/FF/VW/VW.cpp | 18 | ||||
-rw-r--r-- | moses/FF/VW/VW.h | 4 |
2 files changed, 20 insertions, 2 deletions
diff --git a/moses/FF/VW/VW.cpp b/moses/FF/VW/VW.cpp index 5111ff8ed..06acac6c6 100644 --- a/moses/FF/VW/VW.cpp +++ b/moses/FF/VW/VW.cpp @@ -273,13 +273,16 @@ void VW::EvaluateTranslationOptionListWithSourceContext(const InputType &input targetContext.AddWord(m_sentenceStartWord); const Phrase *targetSent = GetStored()->m_sentence; - const AlignmentInfo *alignInfo = GetStored()->m_alignment; + + // word alignment info shifted by context size + AlignmentInfo contextAlignment = TransformAlignmentInfo(*GetStored()->m_alignment, maxContextSize, currentStart); + if (currentStart > 0) targetContext.Append(targetSent->GetSubString(Range(0, currentStart - 1))); // extract target-context features for(size_t i = 0; i < contextFeatures.size(); ++i) - (*contextFeatures[i])(input, targetContext, *alignInfo, classifier, dummyVector); + (*contextFeatures[i])(input, targetContext, contextAlignment, classifier, dummyVector); // go over topts, extract target side features and train the classifier for (size_t toptIdx = 0; toptIdx < translationOptionList.size(); toptIdx++) { @@ -479,6 +482,17 @@ const AlignmentInfo *VW::TransformAlignmentInfo(const Hypothesis &curHypo, size_ return AlignmentInfoCollection::Instance().Add(alignmentPoints); } +AlignmentInfo VW::TransformAlignmentInfo(const AlignmentInfo &alignInfo, size_t contextSize, int currentStart) const { + std::set<std::pair<size_t, size_t> > alignmentPoints; + for (int i = std::max(0, currentStart - (int)contextSize); i < currentStart; i++) { + std::set<size_t> alignedToTgt = alignInfo.GetAlignmentsForTarget(i); + BOOST_FOREACH(size_t srcIdx, alignedToTgt) { + alignmentPoints.insert(std::make_pair(srcIdx, i + contextSize)); + } + } + return AlignmentInfo(alignmentPoints); +} + std::pair<bool, int> VW::IsCorrectTranslationOption(const TranslationOption &topt) const { //std::cerr << topt.GetSourceWordsRange() << std::endl; diff --git a/moses/FF/VW/VW.h b/moses/FF/VW/VW.h index ea17188f7..89891e725 100644 --- a/moses/FF/VW/VW.h +++ b/moses/FF/VW/VW.h @@ -153,6 +153,10 @@ private: // to positions in contextPhrase) const AlignmentInfo *TransformAlignmentInfo(const Hypothesis &curHypo, size_t contextSize) const; + // used during training to extract relevant alignment points from the full sentence alignment + // and shift them by target context size + AlignmentInfo TransformAlignmentInfo(const AlignmentInfo &alignInfo, size_t contextSize, int currentStart) const; + // At training time, determine whether a translation option is correct for the current target sentence // based on word alignment. This is a bit complicated because we need to handle various corner-cases // where some word(s) on phrase borders are unaligned. |