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

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Junczys-Dowmunt <junczys@amu.edu.pl>2017-03-30 17:42:12 +0300
committerMarcin Junczys-Dowmunt <junczys@amu.edu.pl>2017-03-30 17:42:12 +0300
commit2d90e87009408e7dc251ca1310b6d44f87670665 (patch)
tree17c6603a2acff6b887deb5b9f499e6b582b17f5d
parent25b87e14debb2bd711b3ec45a85c815518bb570b (diff)
QE scorerQE
-rw-r--r--mert/Jamfile1
-rw-r--r--mert/QEScorer.cpp83
-rw-r--r--mert/QEScorer.h39
-rw-r--r--mert/ScorerFactory.cpp4
4 files changed, 127 insertions, 0 deletions
diff --git a/mert/Jamfile b/mert/Jamfile
index e3f083864..bfae2aa44 100644
--- a/mert/Jamfile
+++ b/mert/Jamfile
@@ -33,6 +33,7 @@ HwcmScorer.cpp
InternalTree.cpp
M2.cpp
M2Scorer.cpp
+QEScorer.cpp
Scorer.cpp
ScorerFactory.cpp
Optimizer.cpp
diff --git a/mert/QEScorer.cpp b/mert/QEScorer.cpp
new file mode 100644
index 000000000..30ab27bcb
--- /dev/null
+++ b/mert/QEScorer.cpp
@@ -0,0 +1,83 @@
+#include "QEScorer.h"
+
+#include <algorithm>
+#include <fstream>
+#include <stdexcept>
+#include <sstream>
+#include <cstdlib>
+
+#include <boost/lexical_cast.hpp>
+
+
+using namespace std;
+
+namespace MosesTuning
+{
+
+QEScorer::QEScorer(const string& config)
+ : StatisticsBasedScorer("QE", config), bad_(false)
+{
+ const std::string type = getConfig("type", "mult");
+ if(type == "bad")
+ bad_ = true;
+}
+
+void QEScorer::setReferenceFiles(const vector<string>& referenceFiles)
+{}
+
+void QEScorer::prepareStats(size_t sid, const string& text, ScoreStats& entry)
+{}
+
+float QEScorer::calculateScore(const vector<ScoreStatsType>& comps) const
+{
+
+ if (comps.size() != NumberOfScores()) {
+ throw runtime_error("Size of stat vector for QE is not " + NumberOfScores());
+ }
+
+ float p1 = 0.0;
+ float r1 = 0.0;
+ float f1 = 0.0;
+
+ float p2 = 0.0;
+ float r2 = 0.0;
+ float f2 = 0.0;
+
+ if(comps[0] != 0)
+ p1 = (float)comps[0] / (comps[0] + comps[1]);
+ else
+ p1 = 1.0;
+
+ if(comps[2] != 0)
+ r1 = (float)comps[0] / (comps[0] + comps[2]);
+ else
+ r1 = 1.0;
+
+ float denom1 = p1 + r1;
+ if(denom1 != 0)
+ f1 = 2 * p1 * r1 / denom1;
+ else
+ f1 = 0.0;
+
+ if(comps[3] != 0)
+ p2 = (float)comps[3] / (comps[3] + comps[1]);
+ else
+ p2 = 1.0;
+
+ if(comps[2] != 0)
+ r2 = (float)comps[3] / (comps[3] + comps[2]);
+ else
+ r2 = 1.0;
+
+ float denom2 = p2 + r2;
+ if(denom2 != 0)
+ f2 = 2 * p2 * r2 / denom2;
+ else
+ f2 = 0.0;
+
+ if(bad_)
+ return f1;
+ return f1 * f2;
+}
+
+}
diff --git a/mert/QEScorer.h b/mert/QEScorer.h
new file mode 100644
index 000000000..6b4da0fee
--- /dev/null
+++ b/mert/QEScorer.h
@@ -0,0 +1,39 @@
+#ifndef MERT_QE_SCORER_H_
+#define MERT_QE_SCORER_H_
+
+#include <string>
+#include <vector>
+#include <functional>
+
+#include "Types.h"
+#include "Util.h"
+#include "StatisticsBasedScorer.h"
+#include "M2.h"
+
+namespace MosesTuning
+{
+
+class QEScorer: public StatisticsBasedScorer
+{
+public:
+ explicit QEScorer(const std::string& config);
+
+ virtual void setReferenceFiles(const std::vector<std::string>& referenceFiles);
+ virtual void prepareStats(std::size_t sid, const std::string& text, ScoreStats& entry);
+
+ virtual std::size_t NumberOfScores() const {
+ return 4;
+ }
+
+ virtual float calculateScore(const std::vector<ScoreStatsType>& comps) const;
+ virtual float getReferenceLength(const std::vector<ScoreStatsType>& comps) const { return 0; };
+
+private:
+ // no copying allowed
+ QEScorer(const QEScorer&);
+ QEScorer& operator=(const QEScorer&);
+ bool bad_;
+};
+
+}
+#endif // MERT_QE_SCORER_H_
diff --git a/mert/ScorerFactory.cpp b/mert/ScorerFactory.cpp
index 8827f3e5d..de579e996 100644
--- a/mert/ScorerFactory.cpp
+++ b/mert/ScorerFactory.cpp
@@ -12,6 +12,7 @@
#include "PermutationScorer.h"
#include "MeteorScorer.h"
#include "M2Scorer.h"
+#include "QEScorer.h"
#include "HwcmScorer.h"
#include "Reference.h"
@@ -36,6 +37,7 @@ vector<string> ScorerFactory::getTypes()
types.push_back(string("METEOR"));
types.push_back(string("HWCM"));
types.push_back(string("M2SCORER"));
+ types.push_back(string("QE"));
return types;
}
@@ -58,6 +60,8 @@ Scorer* ScorerFactory::getScorer(const string& type, const string& config)
return new SemposScorer(config);
} else if (type == "M2SCORER") {
return new M2Scorer(config);
+ } else if (type == "QE") {
+ return new QEScorer(config);
} else if ((type == "HAMMING") || (type == "KENDALL")) {
return (PermutationScorer*) new PermutationScorer(type, config);
} else if (type == "METEOR") {