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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
#include "comb_scorer.h"
#include <cstdio>
using namespace std;
class BLEUTERCombinationScore : public ScoreBase<BLEUTERCombinationScore> {
friend class BLEUTERCombinationScorer;
public:
~BLEUTERCombinationScore();
float ComputePartialScore() const { return 0.0;}
float ComputeScore() const {
return (bleu->ComputeScore() - ter->ComputeScore()) / 2.0f;
}
void ScoreDetails(string* details) const {
char buf[160];
sprintf(buf, "Combi = %.2f, BLEU = %.2f, TER = %.2f",
ComputeScore()*100.0f, bleu->ComputeScore()*100.0f, ter->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 BLEUTERCombinationScore&>(delta).bleu, scale);
ter->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).ter, scale);
}
void PlusEquals(const Score& delta) {
bleu->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).bleu);
ter->PlusEquals(*static_cast<const BLEUTERCombinationScore&>(delta).ter);
}
ScoreP GetOne() const {
BLEUTERCombinationScore* res = new BLEUTERCombinationScore;
res->bleu = bleu->GetOne();
res->ter = ter->GetOne();
return ScoreP(res);
}
ScoreP GetZero() const {
BLEUTERCombinationScore* res = new BLEUTERCombinationScore;
res->bleu = bleu->GetZero();
res->ter = ter->GetZero();
return ScoreP(res);
}
void Subtract(const Score& rhs, Score* res) const {
bleu->Subtract(*static_cast<const BLEUTERCombinationScore&>(rhs).bleu,
static_cast<BLEUTERCombinationScore*>(res)->bleu.get());
ter->Subtract(*static_cast<const BLEUTERCombinationScore&>(rhs).ter,
static_cast<BLEUTERCombinationScore*>(res)->ter.get());
}
void Encode(std::string* out) const {
string bs, ts;
bleu->Encode(&bs);
ter->Encode(&ts);
out->clear();
(*out) += static_cast<char>(bs.size());
(*out) += bs;
(*out) += ts;
}
bool IsAdditiveIdentity() const {
return bleu->IsAdditiveIdentity() && ter->IsAdditiveIdentity();
}
private:
ScoreP bleu;
ScoreP ter;
};
BLEUTERCombinationScore::~BLEUTERCombinationScore() {
}
BLEUTERCombinationScorer::BLEUTERCombinationScorer(const vector<vector<WordID> >& refs) {
bleu_ = SentenceScorer::CreateSentenceScorer(IBM_BLEU, refs);
ter_ = SentenceScorer::CreateSentenceScorer(TER, refs);
}
BLEUTERCombinationScorer::~BLEUTERCombinationScorer() {
}
ScoreP BLEUTERCombinationScorer::ScoreCCandidate(const vector<WordID>& hyp) const {
return ScoreP();
}
ScoreP BLEUTERCombinationScorer::ScoreCandidate(const std::vector<WordID>& hyp) const {
BLEUTERCombinationScore* res = new BLEUTERCombinationScore;
res->bleu = bleu_->ScoreCandidate(hyp);
res->ter = ter_->ScoreCandidate(hyp);
return ScoreP(res);
}
ScoreP BLEUTERCombinationScorer::ScoreFromString(const std::string& in) {
int bss = in[0];
BLEUTERCombinationScore* r = new BLEUTERCombinationScore;
r->bleu = SentenceScorer::CreateScoreFromString(IBM_BLEU, in.substr(1, bss));
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);
}
|