summaryrefslogtreecommitdiff
path: root/mteval/comb_scorer.cc
diff options
context:
space:
mode:
authoraustinma <austinma@cs.cmu.edu>2016-01-14 21:22:56 -0500
committeraustinma <austinma@cs.cmu.edu>2016-01-14 21:22:56 -0500
commitc643ef361eea7ce43b4fc7a6e2461a01b3d0c3c6 (patch)
treea90a3dbd3e8b6887f8cbf4e5a27994de6eee5d35 /mteval/comb_scorer.cc
parent899032c9728c7a1c9c97f624ba0cc49b0814277b (diff)
Added character-level BLEU metric
Diffstat (limited to 'mteval/comb_scorer.cc')
-rw-r--r--mteval/comb_scorer.cc93
1 files changed, 93 insertions, 0 deletions
diff --git a/mteval/comb_scorer.cc b/mteval/comb_scorer.cc
index 9fc37868..63f327ca 100644
--- a/mteval/comb_scorer.cc
+++ b/mteval/comb_scorer.cc
@@ -95,3 +95,96 @@ ScoreP BLEUTERCombinationScorer::ScoreFromString(const std::string& in) {
r->ter = SentenceScorer::CreateScoreFromString(TER, in.substr(1 + bss));
return ScoreP(r);
}
+
+
+class BLEUCBLEUCombinationScore : public ScoreBase<BLEUCBLEUCombinationScore> {
+ friend class BLEUCBLEUCombinationScorer;
+ public:
+ ~BLEUCBLEUCombinationScore();
+ float ComputePartialScore() const { return 0.0;}
+ float ComputeScore() const {
+ return (bleu->ComputeScore() + cbleu->ComputeScore()) / 2.0f;
+ }
+ void ScoreDetails(string* details) const {
+ char buf[160];
+ sprintf(buf, "Combi = %.2f, BLEU = %.2f, CBLEU = %.2f",
+ ComputeScore()*100.0f, bleu->ComputeScore()*100.0f, cbleu->ComputeScore()*100.0f);
+ *details = buf;
+ }
+ void PlusPartialEquals(const Score& rhs, int oracle_e_cover, int oracle_f_cover, int src_len){}
+
+ void PlusEquals(const Score& delta, const float scale) {
+ bleu->PlusEquals(*static_cast<const BLEUCBLEUCombinationScore&>(delta).bleu, scale);
+ cbleu->PlusEquals(*static_cast<const BLEUCBLEUCombinationScore&>(delta).cbleu, scale);
+ }
+ void PlusEquals(const Score& delta) {
+ bleu->PlusEquals(*static_cast<const BLEUCBLEUCombinationScore&>(delta).bleu);
+ cbleu->PlusEquals(*static_cast<const BLEUCBLEUCombinationScore&>(delta).cbleu);
+ }
+
+
+
+ ScoreP GetOne() const {
+ BLEUCBLEUCombinationScore* res = new BLEUCBLEUCombinationScore;
+ res->bleu = bleu->GetOne();
+ res->cbleu = cbleu->GetOne();
+ return ScoreP(res);
+ }
+ ScoreP GetZero() const {
+ BLEUCBLEUCombinationScore* res = new BLEUCBLEUCombinationScore;
+ res->bleu = bleu->GetZero();
+ res->cbleu = cbleu->GetZero();
+ return ScoreP(res);
+ }
+ void Subtract(const Score& rhs, Score* res) const {
+ bleu->Subtract(*static_cast<const BLEUCBLEUCombinationScore&>(rhs).bleu,
+ static_cast<BLEUCBLEUCombinationScore*>(res)->bleu.get());
+ cbleu->Subtract(*static_cast<const BLEUCBLEUCombinationScore&>(rhs).cbleu,
+ static_cast<BLEUCBLEUCombinationScore*>(res)->cbleu.get());
+ }
+ void Encode(std::string* out) const {
+ string bs, ts;
+ bleu->Encode(&bs);
+ cbleu->Encode(&ts);
+ out->clear();
+ (*out) += static_cast<char>(bs.size());
+ (*out) += bs;
+ (*out) += ts;
+ }
+ bool IsAdditiveIdentity() const {
+ return bleu->IsAdditiveIdentity() && cbleu->IsAdditiveIdentity();
+ }
+ private:
+ ScoreP bleu;
+ ScoreP cbleu;
+};
+
+BLEUCBLEUCombinationScore::~BLEUCBLEUCombinationScore() {
+}
+
+BLEUCBLEUCombinationScorer::BLEUCBLEUCombinationScorer(const vector<vector<WordID> >& refs) {
+ bleu_ = SentenceScorer::CreateSentenceScorer(IBM_BLEU, refs);
+ cbleu_ = SentenceScorer::CreateSentenceScorer(CBLEU, refs);
+}
+
+BLEUCBLEUCombinationScorer::~BLEUCBLEUCombinationScorer() {
+}
+
+ScoreP BLEUCBLEUCombinationScorer::ScoreCCandidate(const vector<WordID>& hyp) const {
+ return ScoreP();
+}
+
+ScoreP BLEUCBLEUCombinationScorer::ScoreCandidate(const std::vector<WordID>& hyp) const {
+ BLEUCBLEUCombinationScore* res = new BLEUCBLEUCombinationScore;
+ res->bleu = bleu_->ScoreCandidate(hyp);
+ res->cbleu = cbleu_->ScoreCandidate(hyp);
+ return ScoreP(res);
+}
+
+ScoreP BLEUCBLEUCombinationScorer::ScoreFromString(const std::string& in) {
+ int bss = in[0];
+ BLEUCBLEUCombinationScore* r = new BLEUCBLEUCombinationScore;
+ r->bleu = SentenceScorer::CreateScoreFromString(IBM_BLEU, in.substr(1, bss));
+ r->cbleu = SentenceScorer::CreateScoreFromString(CBLEU, in.substr(1 + bss));
+ return ScoreP(r);
+}