Welcome to mirror list, hosted at ThFree Co, Russian Federation.

GlobalLexicalModel.h « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3105cb4668a3c7c23dfe164027b36482ac94de41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#ifndef moses_GlobalLexicalModel_h
#define moses_GlobalLexicalModel_h

#include <string>
#include <vector>
#include "Factor.h"
#include "Phrase.h"
#include "TypeDef.h"
#include "Util.h"
#include "WordsRange.h"
#include "ScoreProducer.h"
#include "FeatureFunction.h"
#include "FactorTypeSet.h"
#include "Sentence.h"

#ifdef WITH_THREADS
#include <boost/thread/tss.hpp>
#endif

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
 */

class GlobalLexicalModel : public StatelessFeatureFunction
{
  typedef std::map< const Word*, std::map< const Word*, float, WordComparer >, WordComparer > DoubleHash;
  typedef std::map< const Word*, float, WordComparer > SingleHash;
  typedef std::map< const TargetPhrase*, float > LexiconCache;

  struct ThreadLocalStorage
  {
    LexiconCache cache;
    const Sentence *input;
  };

private:
  DoubleHash m_hash;
#ifdef WITH_THREADS
  boost::thread_specific_ptr<ThreadLocalStorage> m_local;
#else
  std::auto_ptr<ThreadLocalStorage> m_local;
#endif
  std::map< const TargetPhrase*, float > *m_cache;
  const Sentence *m_input;
  Word *m_bias;

  FactorMask m_inputFactors;
  FactorMask m_outputFactors;

  void LoadData(const std::string &filePath,
                const std::vector< FactorType >& inFactors,
                const std::vector< FactorType >& outFactors);

  float ScorePhrase( const TargetPhrase& targetPhrase ) const;
  float GetFromCacheOrScorePhrase( const TargetPhrase& targetPhrase ) const;

public:
	GlobalLexicalModel(const std::string &filePath,
	                   const std::vector< FactorType >& inFactors,
	                   const std::vector< FactorType >& outFactors);
	virtual ~GlobalLexicalModel();

  virtual std::string GetScoreProducerWeightShortName(unsigned) const {
    return "lex";
  };

  void InitializeForInput( Sentence const& in );

  void Evaluate(const TargetPhrase&, ScoreComponentCollection* ) const;

  void EvaluateChart(
    const ChartHypothesis& cur_hypo,
    int featureID,
    ScoreComponentCollection* accumulator) const
  {
  	std::cerr << "EvaluateChart not implemented." << std::endl;
  	exit(1);
  }
};

}
#endif