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

sapt_pscore_pbwd.h « UG « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f7b4686d7c7b9eeab1318c975680c28b34928344 (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
//-*- c++ -*-
// written by Ulrich Germann 
#pragma once
#include "moses/TranslationModel/UG/mm/ug_bitext.h"
#include "util/exception.hh"
#include "boost/format.hpp"
#include "boost/foreach.hpp"

namespace Moses {
  namespace bitext
  {
    template<typename Token>
    class
    PScorePbwd : public PhraseScorer<Token>
    {
      float   conf;
      string denom;
      
    public:
      PScorePbwd(float const c, string d) 
      { 
	this->m_index = -1;
	conf  = c; 
	denom = d;
	size_t checksum = d.size();
	BOOST_FOREACH(char const& x, denom)
	  {
	    if (x == '+') { --checksum; continue; }
	    if (x != 'g' && x != 's' && x != 'r') continue;
	    string s = (format("pbwd-%c%.3f") % x % c).str();
	    this->m_feature_names.push_back(s);
	  }
	this->m_num_feats = this->m_feature_names.size();
	UTIL_THROW_IF2(this->m_feature_names.size() != checksum,
		       "Unknown parameter in specification '"
		       << d << "' for Pbwd phrase scorer at " << HERE);
      }

      void 
      operator()(Bitext<Token> const& bt, 
		 PhrasePair<Token>& pp, 
		 vector<float> * dest = NULL) const
      {
	if (!dest) dest = &pp.fvals;
	// we use the denominator specification to scale the raw counts on the 
	// target side; the clean way would be to counter-sample
	size_t i = this->m_index;
	BOOST_FOREACH(char const& x, denom)
	  {
	    uint32_t m2 = pp.raw2;
	    if      (x == 'g') m2 = round(m2 * float(pp.good1)   / pp.raw1);
	    else if (x == 's') m2 = round(m2 * float(pp.sample1) / pp.raw1);
	    (*dest)[i++] = log(lbop(max(m2, pp.joint),pp.joint,conf));
	  }
      }
    };
  } // namespace bitext
} // namespace Moses