mosesdecoder/moses/ScoreProducer.h

66 lines
1.6 KiB
C
Raw Normal View History

// $Id$
#ifndef moses_ScoreProducer_h
#define moses_ScoreProducer_h
#include <set>
#include <string>
#include <vector>
#include "FeatureVector.h"
namespace Moses
{
/*
* @note do not confuse this with a producer/consumer pattern.
* this is not a producer in that sense.
*/
class ScoreProducer
{
private:
std::string m_description;
bool m_reportSparseFeatures;
size_t m_numScoreComponents;
//In case there's multiple producers with the same description
static std::multiset<std::string> description_counts;
ScoreProducer(const ScoreProducer&); // don't implement
protected:
ScoreProducer(const std::string& description, size_t numScoreComponents);
virtual ~ScoreProducer();
public:
static const size_t unlimited;
static void ResetDescriptionCounts() {
description_counts.clear();
}
//! returns the number of scores that a subclass produces.
//! For example, a language model conventionally produces 1, a translation table some arbitrary number, etc
//! sparse features returned unlimited
size_t GetNumScoreComponents() const {return m_numScoreComponents;}
//! returns a string description of this producer
const std::string& GetScoreProducerDescription() const {return m_description;}
//! returns the number of scores gathered from the input (0 by default)
virtual size_t GetNumInputScores() const {
return 0;
};
Feature function overhaul. Each feature function is computed in one of three ways: 1) Stateless feature functions from the phrase table/generation table: these are computed when the TranslationOption is created. They become part of the ScoreBreakdown object contained in the TranslationOption and are added to the feature value vector when a hypothesis is extended. 2) Stateless feature functions that are computed during state exploration. Currently, only WordPenalty falls into this category, but these functions implement a method Evaluate which do does not receive a Hypothesis or any contextual information. 3) Stateful feature functions: these features receive the arc information (translation option), compute some value and then return some context information. The context information created by a particular feature function is passed back to it as the previous context when a hypothesis originating at the node where the previous edge terminates is created. States in the search space may be recombined if the context information is identical. The context information must be stored in an object implementing the FFState interface. TODO: 1) the command line interface / MERT interface needs to go to named parameters that are otherwise opaque 2) StatefulFeatureFunction's Evaluate method should just take a TranslationOption and a context object. It is not good that it takes a hypothesis, because then people may be tempted to access information about the "previous" hypothesis without "declaring" this dependency. 3) Future cost estimates should be handled using feature functions. All stateful feature functions need some kind of future cost estimate. 4) Philipp's poor-man's cube pruning is broken. git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@2087 1f5c12ca-751b-0410-a591-d2e778427230
2009-02-06 18:43:06 +03:00
virtual bool IsStateless() const = 0;
void SetSparseFeatureReporting() { m_reportSparseFeatures = true; }
bool GetSparseFeatureReporting() const { return m_reportSparseFeatures; }
virtual float GetSparseProducerWeight() const { return 1; }
};
}
#endif