target (internal) bigrams for VW

This commit is contained in:
Ales Tamchyna 2015-02-16 11:36:16 +01:00
parent b05fc4c9bc
commit a46daa1938
3 changed files with 39 additions and 4 deletions

View File

@ -67,10 +67,11 @@
#ifdef HAVE_VW #ifdef HAVE_VW
#include "moses/FF/VW/VW.h" #include "moses/FF/VW/VW.h"
#include "moses/FF/VW/VWFeatureSourceBagOfWords.h" #include "moses/FF/VW/VWFeatureSourceBagOfWords.h"
#include "moses/FF/VW/VWFeatureSourceBigram.h" #include "moses/FF/VW/VWFeatureSourceBigrams.h"
#include "moses/FF/VW/VWFeatureSourceIndicator.h" #include "moses/FF/VW/VWFeatureSourceIndicator.h"
#include "moses/FF/VW/VWFeatureSourcePhraseInternal.h" #include "moses/FF/VW/VWFeatureSourcePhraseInternal.h"
#include "moses/FF/VW/VWFeatureSourceWindow.h" #include "moses/FF/VW/VWFeatureSourceWindow.h"
#include "moses/FF/VW/VWFeatureTargetBigrams.h"
#include "moses/FF/VW/VWFeatureTargetIndicator.h" #include "moses/FF/VW/VWFeatureTargetIndicator.h"
#include "moses/FF/VW/VWFeatureSourceExternalFeatures.h" #include "moses/FF/VW/VWFeatureSourceExternalFeatures.h"
#include "moses/FF/VW/VWFeatureTargetPhraseInternal.h" #include "moses/FF/VW/VWFeatureTargetPhraseInternal.h"
@ -250,10 +251,11 @@ FeatureRegistry::FeatureRegistry()
#ifdef HAVE_VW #ifdef HAVE_VW
MOSES_FNAME(VW); MOSES_FNAME(VW);
MOSES_FNAME(VWFeatureSourceBagOfWords); MOSES_FNAME(VWFeatureSourceBagOfWords);
MOSES_FNAME(VWFeatureSourceBigram); MOSES_FNAME(VWFeatureSourceBigrams);
MOSES_FNAME(VWFeatureSourceIndicator); MOSES_FNAME(VWFeatureSourceIndicator);
MOSES_FNAME(VWFeatureSourcePhraseInternal); MOSES_FNAME(VWFeatureSourcePhraseInternal);
MOSES_FNAME(VWFeatureSourceWindow); MOSES_FNAME(VWFeatureSourceWindow);
MOSES_FNAME(VWFeatureTargetBigrams);
MOSES_FNAME(VWFeatureTargetPhraseInternal); MOSES_FNAME(VWFeatureTargetPhraseInternal);
MOSES_FNAME(VWFeatureTargetIndicator); MOSES_FNAME(VWFeatureTargetIndicator);
MOSES_FNAME(VWFeatureSourceExternalFeatures); MOSES_FNAME(VWFeatureSourceExternalFeatures);

View File

@ -6,10 +6,10 @@
namespace Moses namespace Moses
{ {
class VWFeatureSourceBagOfWords : public VWFeatureSource class VWFeatureSourceBigrams : public VWFeatureSource
{ {
public: public:
VWFeatureSourceBagOfWords(const std::string &line) VWFeatureSourceBigrams(const std::string &line)
: VWFeatureSource(line) { : VWFeatureSource(line) {
ReadParameters(); ReadParameters();

View File

@ -0,0 +1,33 @@
#pragma once
#include <string>
#include "VWFeatureTarget.h"
namespace Moses
{
class VWFeatureTargetBigrams : public VWFeatureTarget
{
public:
VWFeatureTargetBigrams(const std::string &line)
: VWFeatureTarget(line) {
ReadParameters();
VWFeatureBase::UpdateRegister();
}
void operator()(const InputType &input
, const InputPath &inputPath
, const TargetPhrase &targetPhrase
, Discriminative::Classifier &classifier) const {
for (size_t i = 1; i < targetPhrase.GetSize(); i++) {
classifier.AddLabelDependentFeature("tbigram^" + GetWord(targetPhrase, i - 1) + "^" + GetWord(targetPhrase, i));
}
}
virtual void SetParameter(const std::string& key, const std::string& value) {
VWFeatureTarget::SetParameter(key, value);
}
};
}