Merge branch 'master' of github.com:moses-smt/mosesdecoder

This commit is contained in:
Ian Johnson 2013-12-16 13:17:43 +00:00
commit 513e0f1081
14 changed files with 105 additions and 41 deletions

View File

@ -36,7 +36,7 @@ using namespace std;
namespace Moses
{
extern bool g_debug;
extern bool g_mosesDebug;
ChartCellBase::ChartCellBase(size_t startPos, size_t endPos) :
m_coverage(startPos, endPos),

View File

@ -38,7 +38,7 @@ using namespace Moses;
namespace Moses
{
extern bool g_debug;
extern bool g_mosesDebug;
/* constructor. Initialize everything prior to decoding a particular sentence.
* \param source the sentence to be decoded
@ -92,8 +92,8 @@ void ChartManager::ProcessSentence()
// decode
ChartCell &cell = m_hypoStackColl.Get(range);
cell.ProcessSentence(m_translationOptionList, m_hypoStackColl);
m_translationOptionList.Clear();
cell.PruneToSize();
cell.CleanupArcList();

View File

@ -34,7 +34,6 @@ using namespace Moses;
namespace Moses
{
extern bool g_debug;
ChartParserUnknown::ChartParserUnknown() {}

View File

@ -165,4 +165,13 @@ void ChartTranslationOptionList::Evaluate(const InputType &input, const InputPat
}
}
std::ostream& operator<<(std::ostream &out, const ChartTranslationOptionList &obj)
{
for (size_t i = 0; i < obj.m_collection.size(); ++i) {
const ChartTranslationOptions &transOpts = *obj.m_collection[i];
out << transOpts << endl;
}
return out;
}
}

View File

@ -36,6 +36,8 @@ class InputPath;
//! a vector of translations options for a specific range, in a specific sentence
class ChartTranslationOptionList : public ChartParserCallback
{
friend std::ostream& operator<<(std::ostream&, const ChartTranslationOptionList&);
public:
ChartTranslationOptionList(size_t ruleLimit, const InputType &input);
~ChartTranslationOptionList();

View File

@ -135,4 +135,14 @@ void ChartTranslationOptions::CreateSourceRuleFromInputPath()
}
std::ostream& operator<<(std::ostream &out, const ChartTranslationOptions &obj)
{
for (size_t i = 0; i < obj.m_collection.size(); ++i) {
const ChartTranslationOption &transOpt = *obj.m_collection[i];
out << transOpt << endl;
}
return out;
}
}

View File

@ -39,6 +39,8 @@ class InputType;
*/
class ChartTranslationOptions
{
friend std::ostream& operator<<(std::ostream&, const ChartTranslationOptions&);
public:
typedef std::vector<boost::shared_ptr<ChartTranslationOption> > CollType;
@ -57,6 +59,9 @@ public:
static float CalcEstimateOfBestScore(const TargetPhraseCollection &,
const StackVec &);
size_t GetSize() const
{ return m_collection.size(); }
//! @todo dunno
const StackVec &GetStackVec() const {
return m_stackVec;

View File

@ -30,6 +30,15 @@ int ConstrainedDecodingState::Compare(const FFState& other) const
}
//////////////////////////////////////////////////////////////////
ConstrainedDecoding::ConstrainedDecoding(const std::string &line)
:StatefulFeatureFunction(1, line)
,m_maxUnknowns(0)
,m_negate(false)
{
m_tuneable = false;
ReadParameters();
}
void ConstrainedDecoding::Load()
{
const StaticData &staticData = StaticData::Instance();
@ -103,9 +112,18 @@ FFState* ConstrainedDecoding::Evaluate(
float score;
if (hypo.IsSourceCompleted()) {
// translated entire sentence.
score = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize())
? 0 : - std::numeric_limits<float>::infinity();
} else {
bool match = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize());
if (!m_negate) {
score = match ? 0 : - std::numeric_limits<float>::infinity();
}
else {
score = !match ? 0 : - std::numeric_limits<float>::infinity();
}
} else if (m_negate) {
// keep all derivations
score = 0;
}
else {
score = (searchPos != NOT_FOUND) ? 0 : - std::numeric_limits<float>::infinity();
}
@ -133,8 +151,17 @@ FFState* ConstrainedDecoding::EvaluateChart(
if (hypo.GetCurrSourceRange().GetStartPos() == 0 &&
hypo.GetCurrSourceRange().GetEndPos() == source.GetSize() - 1) {
// translated entire sentence.
score = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize())
? 0 : - std::numeric_limits<float>::infinity();
bool match = (searchPos == 0) && (ref->GetSize() == outputPhrase.GetSize());
if (!m_negate) {
score = match ? 0 : - std::numeric_limits<float>::infinity();
}
else {
score = !match ? 0 : - std::numeric_limits<float>::infinity();
}
} else if (m_negate) {
// keep all derivations
score = 0;
} else {
score = (searchPos != NOT_FOUND) ? 0 : - std::numeric_limits<float>::infinity();
}
@ -150,6 +177,8 @@ void ConstrainedDecoding::SetParameter(const std::string& key, const std::string
m_path = value;
} else if (key == "max-unknowns") {
m_maxUnknowns = Scan<int>(value);
} else if (key == "negate") {
m_negate = Scan<bool>(value);
} else {
StatefulFeatureFunction::SetParameter(key, value);
}

View File

@ -33,12 +33,7 @@ protected:
class ConstrainedDecoding : public StatefulFeatureFunction
{
public:
ConstrainedDecoding(const std::string &line)
:StatefulFeatureFunction(1, line)
,m_maxUnknowns(0) {
m_tuneable = false;
ReadParameters();
}
ConstrainedDecoding(const std::string &line);
void Load();
@ -79,6 +74,7 @@ protected:
std::string m_path;
std::map<long,Phrase> m_constraints;
int m_maxUnknowns;
bool m_negate; // only keep translations which DON'T match the reference
};

View File

@ -30,8 +30,11 @@
#include <boost/functional/hash.hpp>
using namespace std;
namespace Moses
{
extern bool g_mosesDebug;
// initialise the RuleCube by creating the top-left corner item
RuleCube::RuleCube(const ChartTranslationOptions &transOpt,
@ -98,4 +101,9 @@ void RuleCube::CreateNeighbor(const RuleCubeItem &item, int dimensionIndex,
}
}
std::ostream& operator<<(std::ostream &out, const RuleCube &obj)
{
out << obj.GetItemSetSize();
return out;
}
}

View File

@ -50,18 +50,6 @@ public:
}
};
/** Define an ordering between RuleCubeItems based on their positions in the
* cube. This is used to record which positions in the cube have been covered
* during search.
*/
class RuleCubeItemPositionOrderer
{
public:
bool operator()(const RuleCubeItem *p, const RuleCubeItem *q) const {
return *p < *q;
}
};
/** @todo what is this?
*/
class RuleCubeItemHasher
@ -69,8 +57,12 @@ class RuleCubeItemHasher
public:
size_t operator()(const RuleCubeItem *p) const {
size_t seed = 0;
boost::hash_combine(seed, p->GetHypothesisDimensions());
boost::hash_combine(seed, p->GetTranslationDimension().GetTranslationOption());
const std::vector<HypothesisDimension> &hypoDim = p->GetHypothesisDimensions();
const ChartTranslationOption *transOpt = p->GetTranslationDimension().GetTranslationOption().get();
boost::hash_combine(seed, hypoDim);
boost::hash_combine(seed, transOpt);
return seed;
}
};
@ -81,8 +73,9 @@ class RuleCubeItemEqualityPred
{
public:
bool operator()(const RuleCubeItem *p, const RuleCubeItem *q) const {
return p->GetHypothesisDimensions() == q->GetHypothesisDimensions() &&
p->GetTranslationDimension() == q->GetTranslationDimension();
bool ret = p->GetHypothesisDimensions() == q->GetHypothesisDimensions() &&
p->GetTranslationDimension() == q->GetTranslationDimension();
return ret;
}
};
@ -90,6 +83,8 @@ public:
*/
class RuleCube
{
friend std::ostream& operator<<(std::ostream &out, const RuleCube &obj);
public:
RuleCube(const ChartTranslationOptions &, const ChartCellCollection &,
ChartManager &);
@ -112,15 +107,14 @@ public:
return m_transOpt;
}
size_t GetItemSetSize() const
{ return m_covered.size(); }
private:
#if defined(BOOST_VERSION) && (BOOST_VERSION >= 104200)
typedef boost::unordered_set<RuleCubeItem*,
RuleCubeItemHasher,
RuleCubeItemEqualityPred
> ItemSet;
#else
typedef std::set<RuleCubeItem*, RuleCubeItemPositionOrderer> ItemSet;
#endif
typedef std::priority_queue<RuleCubeItem*,
std::vector<RuleCubeItem*>,

View File

@ -53,16 +53,16 @@ public:
return m_pos+1 < m_orderedTargetPhrases.size();
}
const boost::shared_ptr<ChartTranslationOption> &GetTranslationOption() const {
const boost::shared_ptr<ChartTranslationOption> GetTranslationOption() const {
return m_orderedTargetPhrases[m_pos];
}
bool operator<(const TranslationDimension &compare) const {
return GetTranslationOption()->GetPhrase() < compare.GetTranslationOption()->GetPhrase();
return GetTranslationOption().get() < compare.GetTranslationOption().get();
}
bool operator==(const TranslationDimension &compare) const {
return GetTranslationOption()->GetPhrase() == compare.GetTranslationOption()->GetPhrase();
return GetTranslationOption().get() == compare.GetTranslationOption().get();
}
private:

View File

@ -51,6 +51,7 @@ using namespace std;
namespace Moses
{
bool g_mosesDebug = false;
StaticData StaticData::s_instance;
@ -552,7 +553,6 @@ bool StaticData::LoadData(Parameter *parameter)
UserMessage::Add("Unable to load weights from " + extraWeightConfig[0]);
return false;
}
m_allWeights.PlusEquals(extraWeights);
}
@ -991,9 +991,18 @@ bool StaticData::LoadAlternateWeightSettings()
// other specifications
for(size_t j=1; j<tokens.size(); j++) {
vector<string> args = Tokenize(tokens[j], "=");
// TODO: support for sparse weights
// sparse weights
if (args[0] == "weight-file") {
cerr << "ERROR: sparse weight files currently not supported";
if (args.size() != 2) {
UserMessage::Add("One argument should be supplied for weight-file");
return false;
}
ScoreComponentCollection extraWeights;
if (!extraWeights.Load(args[1])) {
UserMessage::Add("Unable to load weights from " + args[1]);
return false;
}
m_weightSetting[ currentId ]->PlusEquals(extraWeights);
}
// ignore feature functions
else if (args[0] == "ignore-ff") {

View File

@ -140,6 +140,9 @@ public:
void Merge(const TargetPhrase &copy, const std::vector<FactorType>& factorVec);
bool operator< (const TargetPhrase &compare) const; // NOT IMPLEMENTED
bool operator== (const TargetPhrase &compare) const; // NOT IMPLEMENTED
TO_STRING();
};