mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-19 07:07:24 +03:00
add WP
This commit is contained in:
parent
f00d781c37
commit
2e7d4126db
@ -1,2 +1,17 @@
|
||||
#include "FF.h"
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
std::string FF::OutputFactors(const std::vector<int> &factors) const
|
||||
{
|
||||
if (factors.size() == 0)
|
||||
return "";
|
||||
|
||||
stringstream ret;
|
||||
ret << factors[0];
|
||||
for (size_t i = 1; i < factors.size(); ++i) {
|
||||
ret << "," << factors[i];
|
||||
}
|
||||
return ret.str();
|
||||
}
|
||||
|
@ -9,8 +9,12 @@ class FF
|
||||
{
|
||||
virtual float GetWeight() const = 0;
|
||||
|
||||
protected:
|
||||
std::string OutputFactors(const std::vector<int> &factors) const;
|
||||
|
||||
public:
|
||||
std::vector<std::string> toks;
|
||||
std::vector<int> inFactors, outFactors;
|
||||
std::string name;
|
||||
std::string path;
|
||||
int index, numFeatures;
|
||||
|
@ -15,7 +15,7 @@ class LM : public FF
|
||||
|
||||
void Output(std::ostream &out) const
|
||||
{
|
||||
out << name << index
|
||||
out << name
|
||||
<< " order=" << order
|
||||
<< " factor=" << factor
|
||||
<< " path=" << path
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "LM.h"
|
||||
#include "RO.h"
|
||||
#include "PT.h"
|
||||
#include "WP.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -45,6 +46,9 @@ void Output()
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
WP *model = new WP("");
|
||||
ffVec.push_back(model);
|
||||
|
||||
for (int i = 0; i < argc; ++i) {
|
||||
string key(argv[i]);
|
||||
|
||||
|
@ -4,7 +4,7 @@ int PT::s_index = 0;
|
||||
|
||||
void PT::Output(std::ostream &out) const
|
||||
{
|
||||
out << name << index
|
||||
out << name
|
||||
<< " implementation=" << 0
|
||||
<< " num-features=" << numFeatures
|
||||
<< " path=" << path;
|
||||
|
@ -6,13 +6,18 @@
|
||||
class RO : public FF
|
||||
{
|
||||
static int s_index;
|
||||
|
||||
std::string type;
|
||||
|
||||
float GetWeight() const
|
||||
{ return 0.3; }
|
||||
|
||||
void Output(std::ostream &out) const
|
||||
{
|
||||
out << name << index
|
||||
out << name
|
||||
<< " num-features=" << numFeatures
|
||||
<< " type=" << type
|
||||
<< " input-factor=" << OutputFactors(inFactors)
|
||||
<< " output-factor=" << OutputFactors(outFactors)
|
||||
<< " path=" << path
|
||||
<< std::endl;
|
||||
}
|
||||
@ -25,6 +30,10 @@ public:
|
||||
name = "LexicalReordering";
|
||||
numFeatures = 6;
|
||||
path = toks[0];
|
||||
type = "msd-bidirectional-fe";
|
||||
|
||||
inFactors.push_back(0);
|
||||
outFactors.push_back(0);
|
||||
}
|
||||
|
||||
};
|
||||
|
3
misc/create-ini/WP.cpp
Normal file
3
misc/create-ini/WP.cpp
Normal file
@ -0,0 +1,3 @@
|
||||
#include "WP.h"
|
||||
|
||||
int WP::s_index = 0;
|
26
misc/create-ini/WP.h
Normal file
26
misc/create-ini/WP.h
Normal file
@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "FF.h"
|
||||
|
||||
class WP : public FF
|
||||
{
|
||||
static int s_index;
|
||||
|
||||
virtual float GetWeight() const
|
||||
{ return 0.5; }
|
||||
|
||||
void Output(std::ostream &out) const
|
||||
{
|
||||
out << name
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
public:
|
||||
WP(const std::string &line)
|
||||
:FF(line)
|
||||
{
|
||||
index = s_index++;
|
||||
name = "WordPenalty";
|
||||
numFeatures = 1;
|
||||
}
|
||||
};
|
@ -1 +1 @@
|
||||
g++ FF.cpp LM.cpp RO.cpp PT.cpp Main.cpp -o ../../bin/create-ini
|
||||
g++ FF.cpp LM.cpp RO.cpp PT.cpp WP.cpp Main.cpp -o ../../bin/create-ini
|
||||
|
@ -300,7 +300,8 @@ bool Parameter::LoadParam(int argc, char* argv[])
|
||||
}
|
||||
|
||||
// convert old weights args to new format
|
||||
ConvertWeightArgs();
|
||||
if (isParamSpecified("features"))
|
||||
ConvertWeightArgs();
|
||||
CreateWeightsMap();
|
||||
WeightOverwrite();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user