bleu scorer

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/branches/mira-mtm5@3477 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
hieuhoang1972 2010-09-16 09:54:13 +00:00
parent ade3fee90f
commit aece4437c2
4 changed files with 23 additions and 18 deletions

View File

@ -54,13 +54,13 @@ BleuScoreFeature::BleuScoreFeature() {
}
void BleuScoreFeature::LoadReferences(std::vector<
std::vector< std::string > >refs)
void BleuScoreFeature::LoadReferences(const std::vector<
std::vector< std::string > > &refs)
{
FactorCollection& fc = FactorCollection::Instance();
for (size_t ref_id = 0; ref_id < refs.size(); ref_id++) {
std::vector< std::string >& ref = refs[ref_id];
std::pair< size_t, std::map< Phrase, size_t > > ref_pair;
const std::vector< std::string >& ref = refs[ref_id];
std::pair< size_t, NGrams > ref_pair;
ref_pair.first = ref.size();
for (size_t order = 1; order < BleuScoreState::bleu_order; order++) {
for (size_t end_idx = order; end_idx < ref.size(); end_idx++) {
@ -87,7 +87,7 @@ FFState* BleuScoreFeature::Evaluate(const Hypothesis& cur_hypo,
const FFState* prev_state,
ScoreComponentCollection* accumulator) const
{
std::map< Phrase, size_t >::const_iterator reference_ngrams_iter;
NGrams::const_iterator reference_ngrams_iter;
const BleuScoreState& ps = dynamic_cast<const BleuScoreState&>(*prev_state);
BleuScoreState* new_state = new BleuScoreState(ps);

View File

@ -51,7 +51,7 @@ public:
return 1;
}
void LoadReferences(std::vector< std::vector< std::string > >);
void LoadReferences(const std::vector< std::vector< std::string > > &);
void SetCurrentReference(size_t);
FFState* Evaluate( const Hypothesis& cur_hypo,
@ -61,8 +61,9 @@ public:
const FFState* EmptyHypothesisState(const InputType&) const;
private:
std::map< size_t, std::pair< size_t, std::map< Phrase, size_t > > > m_refs;
std::map< Phrase, size_t > m_cur_ref_ngrams;
typedef std::map< Phrase, size_t > NGrams;
std::map< size_t, std::pair< size_t, NGrams > > m_refs;
NGrams m_cur_ref_ngrams;
size_t m_cur_ref_length;
};

View File

@ -34,6 +34,19 @@ void ScoreComponentCollection::PlusEqualsAllLM(const LMList& lmList, const Score
}
}
void ScoreComponentCollection::PlusEquals(const ScoreProducer* sp, const std::vector<float>& scores)
{
assert(scores.size() == sp->GetNumScoreComponents());
size_t i = m_sim->GetBeginIndex(sp->GetScoreBookkeepingID());
for (std::vector<float>::const_iterator vi = scores.begin();
vi != scores.end(); ++vi)
{
const std::string &name = m_sim->GetFeatureName(i++);
m_scores[name] += *vi;
}
}
std::ostream& operator<<(std::ostream& os, const ScoreComponentCollection& rhs)
{

View File

@ -94,16 +94,7 @@ public:
//! Add scores from a single ScoreProducer only
//! The length of scores must be equal to the number of score components
//! produced by sp
void PlusEquals(const ScoreProducer* sp, const std::vector<float>& scores)
{
assert(scores.size() == sp->GetNumScoreComponents());
size_t i = m_sim->GetBeginIndex(sp->GetScoreBookkeepingID());
for (std::vector<float>::const_iterator vi = scores.begin();
vi != scores.end(); ++vi)
{
m_scores[m_sim->GetFeatureName(i++)] += *vi;
}
}
void PlusEquals(const ScoreProducer* sp, const std::vector<float>& scores);
//! Add scores from a single ScoreProducer only
//! The length of scores must be equal to the number of score components