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

sapt_pscore_logcnt.h « UG « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2790323ed041374542c0037b43ffa70584764ced (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
// -*- c++ -*-
// Phrase scorer that rewards the number of phrase pair occurrences in a bitext
// with the asymptotic function x/(j+x) where x > 0 is a function
// parameter that determines the steepness of the rewards curve
// written by Ulrich Germann 

#include "sapt_pscore_base.h"
#include <boost/dynamic_bitset.hpp>

using namespace std;
namespace Moses {
  namespace bitext  {
    
    template<typename Token>
    class
    PScoreLogCnt : public PhraseScorer<Token>
    {
      string m_specs;
    public:
      PScoreLogCnt(string const specs) 
      { 
	this->m_index = -1;
	this->m_specs = specs;
	if (specs.find("r1") != string::npos) // raw source phrase counts
	  this->m_feature_names.push_back("log-r1");
	if (specs.find("s1") != string::npos)
	  this->m_feature_names.push_back("log-s1"); // L1 sample size
	if (specs.find("g1") != string::npos) // coherent phrases
	  this->m_feature_names.push_back("log-g1");
	if (specs.find("j") != string::npos) // joint counts
	  this->m_feature_names.push_back("log-j");
	if (specs.find("r2") != string::npos) // raw target phrase counts
	  this->m_feature_names.push_back("log-r2");
	this->m_num_feats = this->m_feature_names.size();
      }

      bool
      isIntegerValued(int i) const { return true; } 

      void 
      operator()(Bitext<Token> const& bt, 
		 PhrasePair<Token>& pp, 
		 vector<float> * dest = NULL) const
      {
	if (!dest) dest = &pp.fvals;
	assert(pp.raw1);
	assert(pp.sample1);
	assert(pp.good1);
	assert(pp.joint);
	assert(pp.raw2);
	size_t i = this->m_index;
	if (m_specs.find("r1") != string::npos) 
	  (*dest)[i++] = log(pp.raw1);
	if (m_specs.find("s1") != string::npos) 
	  (*dest)[i++] = log(pp.sample1);
	if (m_specs.find("g1") != string::npos) 
	  (*dest)[i++] = log(pp.good1);
	if (m_specs.find("j") != string::npos) 
	  (*dest)[i++] = log(pp.joint);
	if (m_specs.find("r2") != string::npos) 
	  (*dest)[++i] = log(pp.raw2);
      }
    };
  } // namespace bitext
} // namespace Moses