2012-01-31 14:31:39 +04:00
|
|
|
#ifndef GLOBALLEXICALMODELUNLIMITED_H_
|
|
|
|
#define GLOBALLEXICALMODELUNLIMITED_H_
|
|
|
|
|
2013-05-24 16:04:39 +04:00
|
|
|
#include <stdexcept>
|
2012-01-31 14:31:39 +04:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2013-05-27 03:33:01 +04:00
|
|
|
#include <boost/unordered_set.hpp>
|
|
|
|
#include <boost/unordered_map.hpp>
|
|
|
|
|
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"
|
2012-01-31 14:31:39 +04:00
|
|
|
|
2012-02-04 22:17:57 +04:00
|
|
|
#ifdef WITH_THREADS
|
|
|
|
#include <boost/thread/tss.hpp>
|
|
|
|
#endif
|
|
|
|
|
2012-01-31 14:31:39 +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
|
|
|
|
*/
|
|
|
|
|
2012-04-09 23:47:51 +04:00
|
|
|
class GlobalLexicalModelUnlimited : public StatelessFeatureFunction
|
2012-01-31 14:31:39 +04:00
|
|
|
{
|
2013-05-29 21:16:15 +04:00
|
|
|
typedef std::map< char, short > CharHash;
|
|
|
|
typedef std::map< std::string, short > StringHash;
|
2012-02-04 22:17:57 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
struct ThreadLocalStorage {
|
2015-05-19 04:35:39 +03:00
|
|
|
// const Sentence *input;
|
2012-02-04 22:17:57 +04:00
|
|
|
const Sentence *input;
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef WITH_THREADS
|
|
|
|
boost::thread_specific_ptr<ThreadLocalStorage> m_local;
|
|
|
|
#else
|
|
|
|
std::auto_ptr<ThreadLocalStorage> m_local;
|
|
|
|
#endif
|
|
|
|
|
2012-02-15 15:27:00 +04:00
|
|
|
CharHash m_punctuationHash;
|
2012-02-02 18:21:48 +04:00
|
|
|
|
2012-01-31 14:31:39 +04:00
|
|
|
std::vector< FactorType > m_inputFactors;
|
|
|
|
std::vector< FactorType > m_outputFactors;
|
2012-02-26 21:46:04 +04:00
|
|
|
bool m_unrestricted;
|
|
|
|
|
2012-02-27 00:14:49 +04:00
|
|
|
bool m_sourceContext;
|
2012-02-29 00:22:09 +04:00
|
|
|
bool m_biphrase;
|
|
|
|
bool m_bitrigger;
|
2012-01-31 14:31:39 +04:00
|
|
|
|
2012-03-22 19:04:18 +04:00
|
|
|
bool m_biasFeature;
|
|
|
|
bool m_ignorePunctuation;
|
|
|
|
|
2013-05-27 03:33:01 +04:00
|
|
|
boost::unordered_set<std::string> m_vocabSource;
|
|
|
|
boost::unordered_set<std::string> m_vocabTarget;
|
2012-01-31 14:31:39 +04:00
|
|
|
|
|
|
|
public:
|
2013-01-01 21:27:26 +04:00
|
|
|
GlobalLexicalModelUnlimited(const std::string &line);
|
2012-02-29 00:22:09 +04:00
|
|
|
|
2012-02-27 00:14:49 +04:00
|
|
|
bool Load(const std::string &filePathSource, const std::string &filePathTarget);
|
|
|
|
|
2015-05-19 04:35:39 +03:00
|
|
|
void InitializeForInput(ttasksptr const& ttask);
|
2012-01-31 14:31:39 +04:00
|
|
|
|
2012-09-07 19:57:53 +04:00
|
|
|
//TODO: This implements the old interface, but cannot be updated because
|
|
|
|
//it appears to be stateful
|
2014-07-10 02:41:08 +04:00
|
|
|
void EvaluateWhenApplied(const Hypothesis& cur_hypo,
|
2015-01-14 14:07:42 +03:00
|
|
|
ScoreComponentCollection* accumulator) const;
|
2012-02-29 00:22:09 +04:00
|
|
|
|
2014-07-10 02:54:16 +04:00
|
|
|
void EvaluateWhenApplied(const ChartHypothesis& /* cur_hypo */,
|
2015-01-14 14:07:42 +03:00
|
|
|
int /* featureID */,
|
|
|
|
ScoreComponentCollection* ) const {
|
2013-05-24 16:04:39 +04:00
|
|
|
throw std::logic_error("GlobalLexicalModelUnlimited not supported in chart decoder, yet");
|
2012-02-29 00:22:09 +04:00
|
|
|
}
|
2012-01-31 14:31:39 +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
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection *estimatedScores = NULL) const {
|
2015-01-14 14:07:42 +03: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 {
|
|
|
|
}
|
|
|
|
|
2014-07-10 01:35:59 +04:00
|
|
|
void EvaluateInIsolation(const Phrase &source
|
2015-01-14 14:07:42 +03:00
|
|
|
, const TargetPhrase &targetPhrase
|
|
|
|
, ScoreComponentCollection &scoreBreakdown
|
2015-11-04 18:10:45 +03:00
|
|
|
, ScoreComponentCollection &estimatedScores) const {
|
2015-01-14 14:07:42 +03:00
|
|
|
}
|
2013-08-30 18:49:00 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
void AddFeature(ScoreComponentCollection* accumulator,
|
|
|
|
StringPiece sourceTrigger, StringPiece sourceWord, StringPiece targetTrigger,
|
|
|
|
StringPiece targetWord) const;
|
2012-01-31 14:31:39 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* GLOBALLEXICALMODELUNLIMITED_H_ */
|