2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_GlobalLexicalModel_h
|
|
|
|
#define moses_GlobalLexicalModel_h
|
2009-05-26 23:31:32 +04:00
|
|
|
|
2013-05-24 16:04:39 +04:00
|
|
|
#include <stdexcept>
|
2009-05-26 23:31:32 +04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2012-02-03 04:23:47 +04:00
|
|
|
#include <memory>
|
2013-05-24 22:11:15 +04:00
|
|
|
#include "StatelessFeatureFunction.h"
|
2013-05-24 21:02:49 +04:00
|
|
|
#include "moses/Factor.h"
|
|
|
|
#include "moses/Phrase.h"
|
|
|
|
#include "moses/TypeDef.h"
|
|
|
|
#include "moses/Util.h"
|
2015-10-25 16:37:59 +03:00
|
|
|
#include "moses/Range.h"
|
2013-05-24 21:02:49 +04:00
|
|
|
#include "moses/FactorTypeSet.h"
|
|
|
|
#include "moses/Sentence.h"
|
2009-05-26 23:31:32 +04:00
|
|
|
|
2012-02-16 22:56:33 +04:00
|
|
|
#ifdef WITH_THREADS
|
|
|
|
#include <boost/thread/tss.hpp>
|
|
|
|
#endif
|
|
|
|
|
2009-05-26 23:31:32 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
|
|
|
|
|
|
|
class Factor;
|
|
|
|
class Phrase;
|
|
|
|
class Hypothesis;
|
|
|
|
class InputType;
|
|
|
|
|
|
|
|
/** Discriminatively trained global lexicon model
|
|
|
|
* This is a implementation of Mauser et al., 2009's model that predicts
|
|
|
|
* each output word from _all_ the input words. The intuition behind this
|
|
|
|
* feature is that it uses context words for disambiguation
|
|
|
|
*/
|
2011-02-24 16:14:42 +03:00
|
|
|
class GlobalLexicalModel : public StatelessFeatureFunction
|
|
|
|
{
|
2015-10-18 03:02:38 +03:00
|
|
|
typedef boost::unordered_map< const Word*,
|
2015-10-18 15:30:02 +03:00
|
|
|
boost::unordered_map< const Word*, float, UnorderedComparer<Word> , UnorderedComparer<Word> >,
|
|
|
|
UnorderedComparer<Word>, UnorderedComparer<Word> > DoubleHash;
|
2015-10-18 03:02:38 +03:00
|
|
|
typedef boost::unordered_map< const Word*, float, UnorderedComparer<Word>, UnorderedComparer<Word> > SingleHash;
|
2012-02-16 22:56:33 +04:00
|
|
|
typedef std::map< const TargetPhrase*, float > LexiconCache;
|
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
struct ThreadLocalStorage {
|
2012-02-16 22:56:33 +04:00
|
|
|
LexiconCache cache;
|
|
|
|
const Sentence *input;
|
|
|
|
};
|
|
|
|
|
2009-05-26 23:31:32 +04:00
|
|
|
private:
|
2011-02-24 16:14:42 +03:00
|
|
|
DoubleHash m_hash;
|
2012-02-16 22:56:33 +04:00
|
|
|
#ifdef WITH_THREADS
|
|
|
|
boost::thread_specific_ptr<ThreadLocalStorage> m_local;
|
|
|
|
#else
|
|
|
|
std::auto_ptr<ThreadLocalStorage> m_local;
|
|
|
|
#endif
|
2011-02-24 16:14:42 +03:00
|
|
|
Word *m_bias;
|
|
|
|
|
2013-06-11 02:16:28 +04:00
|
|
|
FactorMask m_inputFactors, m_outputFactors;
|
|
|
|
std::vector<FactorType> m_inputFactorsVec, m_outputFactorsVec;
|
|
|
|
std::string m_filePath;
|
2009-05-26 23:31:32 +04:00
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
void Load(AllOptions::ptr const& opts);
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
float ScorePhrase( const TargetPhrase& targetPhrase ) const;
|
|
|
|
float GetFromCacheOrScorePhrase( const TargetPhrase& targetPhrase ) const;
|
2009-05-26 23:31:32 +04:00
|
|
|
|
|
|
|
public:
|
2012-12-31 20:41:33 +04:00
|
|
|
GlobalLexicalModel(const std::string &line);
|
2013-05-29 21:16:15 +04:00
|
|
|
virtual ~GlobalLexicalModel();
|
2009-05-26 23:31:32 +04:00
|
|
|
|
2013-08-30 18:49:00 +04:00
|
|
|
void SetParameter(const std::string& key, const std::string& value);
|
|
|
|
|
2015-05-19 04:35:39 +03:00
|
|
|
void InitializeForInput(ttasksptr const& ttask);
|
2009-05-26 23:31:32 +04:00
|
|
|
|
2013-05-30 15:41:08 +04:00
|
|
|
bool IsUseable(const FactorMask &mask) const;
|
|
|
|
|
2014-10-13 13:42:25 +04:00
|
|
|
void EvaluateInIsolation(const Phrase &source
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2016-05-03 13:01:43 +03:00
|
|
|
, ScoreComponentCollection &estimatedScores) const {
|
2016-05-11 02:00:37 +03:00
|
|
|
}
|
2012-04-09 23:47:51 +04:00
|
|
|
|
2014-10-13 13:42:25 +04:00
|
|
|
void EvaluateWhenApplied(const Hypothesis& hypo,
|
2015-01-14 14:07:42 +03:00
|
|
|
ScoreComponentCollection* accumulator) const {
|
|
|
|
}
|
2014-10-13 13:42:25 +04:00
|
|
|
void EvaluateWhenApplied(const ChartHypothesis &hypo,
|
2015-01-14 14:07:42 +03:00
|
|
|
ScoreComponentCollection* accumulator) const {
|
|
|
|
}
|
2013-08-30 18:49:00 +04:00
|
|
|
|
2014-07-10 02:06:54 +04:00
|
|
|
void EvaluateWithSourceContext(const InputType &input
|
2015-01-14 14:07:42 +03:00
|
|
|
, const InputPath &inputPath
|
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, const StackVec *stackVec
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2016-05-03 13:01:43 +03:00
|
|
|
, ScoreComponentCollection *estimatedScores = NULL) const;
|
2013-04-30 22:27:49 +04:00
|
|
|
|
2015-01-06 15:56:13 +03:00
|
|
|
void EvaluateTranslationOptionListWithSourceContext(const InputType &input
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TranslationOptionList &translationOptionList) const {
|
|
|
|
}
|
|
|
|
|
2009-05-26 23:31:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|