This commit is contained in:
Hieu Hoang 2013-02-13 21:00:51 +00:00
parent f00d781c37
commit 2e7d4126db
10 changed files with 68 additions and 6 deletions

View File

@ -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();
}

View File

@ -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;

View File

@ -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

View File

@ -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]);

View File

@ -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;

View File

@ -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
View File

@ -0,0 +1,3 @@
#include "WP.h"
int WP::s_index = 0;

26
misc/create-ini/WP.h Normal file
View 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;
}
};

View File

@ -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

View File

@ -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();