mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-11 11:25:40 +03:00
get rid of TargetPhrase::SetScore. Expose ScorerBreakdown object so they can be set directly
This commit is contained in:
parent
d108149c3c
commit
499487fb98
@ -244,7 +244,7 @@ Moses::TargetPhrase *TargetPhrase::ConvertToMoses(const std::vector<Moses::Facto
|
||||
}
|
||||
|
||||
// scores
|
||||
ret->SetScore(&phraseDict, m_scores);
|
||||
ret->GetScoreBreakdown().Assign(&phraseDict, m_scores);
|
||||
ret->Evaluate();
|
||||
|
||||
// alignments
|
||||
|
@ -134,8 +134,8 @@ void ChartManager::AddXmlChartOptions() {
|
||||
i != xmlChartOptionsList.end(); ++i) {
|
||||
ChartTranslationOptions* opt = *i;
|
||||
|
||||
Moses::Scores wordPenaltyScore(1, -1);
|
||||
opt->GetTargetPhraseCollection().GetCollection()[0]->SetScore((FeatureFunction*)staticData.GetWordPenaltyProducer(), wordPenaltyScore);
|
||||
TargetPhrase &targetPhrase = *opt->GetTargetPhraseCollection().GetCollection()[0];
|
||||
targetPhrase.GetScoreBreakdown().Assign(staticData.GetWordPenaltyProducer(), -1);
|
||||
|
||||
const WordsRange &range = opt->GetSourceWordsRange();
|
||||
RuleCubeItem* item = new RuleCubeItem( *opt, m_hypoStackColl );
|
||||
|
@ -44,7 +44,6 @@ void ChartParserUnknown::Process(const Word &sourceWord, const WordsRange &range
|
||||
// unknown word, add as trans opt
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const UnknownWordPenaltyProducer *unknownWordPenaltyProducer = staticData.GetUnknownWordPenaltyProducer();
|
||||
vector<float> wordPenaltyScore(1, -1);
|
||||
|
||||
size_t isDigit = 0;
|
||||
if (staticData.GetDropUnknown()) {
|
||||
@ -84,11 +83,11 @@ void ChartParserUnknown::Process(const Word &sourceWord, const WordsRange &range
|
||||
targetWord.CreateUnknownWord(sourceWord);
|
||||
|
||||
// scores
|
||||
vector<float> unknownScore(1, FloorScore(TransformScore(prob)));
|
||||
|
||||
//targetPhrase->SetScore();
|
||||
targetPhrase->SetScore(unknownWordPenaltyProducer, unknownScore);
|
||||
targetPhrase->SetScore(staticData.GetWordPenaltyProducer(), wordPenaltyScore);
|
||||
float unknownScore = FloorScore(TransformScore(prob));
|
||||
|
||||
targetPhrase->GetScoreBreakdown().Assign(unknownWordPenaltyProducer, unknownScore);
|
||||
targetPhrase->Evaluate();
|
||||
|
||||
targetPhrase->SetSourcePhrase(*unksrc);
|
||||
targetPhrase->SetTargetLHS(targetLHS);
|
||||
targetPhrase->SetAlignmentInfo("0-0");
|
||||
@ -98,7 +97,7 @@ void ChartParserUnknown::Process(const Word &sourceWord, const WordsRange &range
|
||||
} // for (iterLHS
|
||||
} else {
|
||||
// drop source word. create blank trans opt
|
||||
vector<float> unknownScore(1, FloorScore(-numeric_limits<float>::infinity()));
|
||||
float unknownScore = FloorScore(-numeric_limits<float>::infinity());
|
||||
|
||||
TargetPhrase *targetPhrase = new TargetPhrase();
|
||||
// loop
|
||||
@ -112,8 +111,10 @@ void ChartParserUnknown::Process(const Word &sourceWord, const WordsRange &range
|
||||
targetLHS.CreateFromString(Output, staticData.GetOutputFactorOrder(), targetLHSStr, true);
|
||||
CHECK(targetLHS.GetFactor(0) != NULL);
|
||||
|
||||
targetPhrase->GetScoreBreakdown().Assign(unknownWordPenaltyProducer, unknownScore);
|
||||
targetPhrase->Evaluate();
|
||||
|
||||
targetPhrase->SetSourcePhrase(*unksrc);
|
||||
targetPhrase->SetScore(unknownWordPenaltyProducer, unknownScore);
|
||||
targetPhrase->SetTargetLHS(targetLHS);
|
||||
|
||||
// chart rule
|
||||
|
@ -287,7 +287,7 @@ protected:
|
||||
|
||||
targetPhrase.SetSourcePhrase(*srcPtr);
|
||||
|
||||
targetPhrase.SetScore(m_obj, scoreVector);
|
||||
targetPhrase.GetScoreBreakdown().Assign(m_obj, scoreVector);
|
||||
targetPhrase.Evaluate();
|
||||
}
|
||||
|
||||
|
@ -103,11 +103,14 @@ void TargetPhrase::SetXMLScore(float score)
|
||||
const FeatureFunction* prod = staticData.GetPhraseDictionaries()[0];
|
||||
size_t numScores = prod->GetNumScoreComponents();
|
||||
vector <float> scoreVector(numScores,score/numScores);
|
||||
SetScore(prod, scoreVector);
|
||||
|
||||
m_scoreBreakdown.Assign(prod, scoreVector);
|
||||
}
|
||||
|
||||
void TargetPhrase::SetInputScore(const Scores &scoreVector)
|
||||
{
|
||||
cerr << scoreVector.size() << endl;
|
||||
|
||||
//we use an existing score producer to figure out information for score setting (number of scores and weights)
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const FeatureFunction* prod = staticData.GetPhraseDictionaries()[0];
|
||||
@ -117,15 +120,7 @@ void TargetPhrase::SetInputScore(const Scores &scoreVector)
|
||||
Scores sizedScoreVector = scoreVector;
|
||||
sizedScoreVector.resize(prod->GetNumScoreComponents(),0.0f);
|
||||
|
||||
SetScore(prod, sizedScoreVector);
|
||||
}
|
||||
|
||||
// used to set translation or gen score
|
||||
void TargetPhrase::SetScore(const FeatureFunction* producer, const Scores &scoreVector)
|
||||
{
|
||||
// used when creating translations of unknown words (chart decoding)
|
||||
m_scoreBreakdown.Assign(producer, scoreVector);
|
||||
m_fullScore = m_scoreBreakdown.GetWeightedScore();
|
||||
m_scoreBreakdown.Assign(prod, sizedScoreVector);
|
||||
}
|
||||
|
||||
TargetPhrase *TargetPhrase::MergeNext(const TargetPhrase &inputPhrase) const
|
||||
|
@ -65,7 +65,6 @@ public:
|
||||
void SetSparseScore(const FeatureFunction* translationScoreProducer, const StringPiece &sparseString);
|
||||
|
||||
// used to set translation or gen score
|
||||
void SetScore(const FeatureFunction* producer, const Scores &scoreVector);
|
||||
void SetXMLScore(float score);
|
||||
void SetInputScore(const Scores &scoreVector);
|
||||
|
||||
|
@ -439,7 +439,7 @@ TargetPhraseVectorPtr PhraseDecoder::DecodeCollection(
|
||||
|
||||
if(scores.size() == m_numScoreComponent)
|
||||
{
|
||||
targetPhrase->SetScore(&m_phraseDictionary, scores);
|
||||
targetPhrase->GetScoreBreakdown().Assign(&m_phraseDictionary, scores);
|
||||
targetPhrase->Evaluate();
|
||||
|
||||
if(m_containsAlignmentInfo)
|
||||
|
@ -52,7 +52,7 @@ const TargetPhraseCollection *PhraseDictionaryDynSuffixArray::GetTargetPhraseCol
|
||||
//std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),NegateScore);
|
||||
std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),FloorScore);
|
||||
|
||||
targetPhrase->SetScore(this, scoreVector);
|
||||
targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
|
||||
targetPhrase->Evaluate();
|
||||
|
||||
//cout << *targetPhrase << "\t" << std::setprecision(8) << scoreVector[2] << endl;
|
||||
|
@ -150,7 +150,7 @@ void PhraseDictionaryMultiModel::CollectSufficientStatistics(const Phrase& src,
|
||||
scoreVector[j] = -raw_scores[j];
|
||||
}
|
||||
|
||||
statistics->targetPhrase->SetScore(this, scoreVector); // set scores to 0
|
||||
statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector); // set scores to 0
|
||||
|
||||
(*allStats)[targetString] = statistics;
|
||||
|
||||
@ -187,7 +187,7 @@ TargetPhraseCollection* PhraseDictionaryMultiModel::CreateTargetPhraseCollection
|
||||
for (size_t i = 0; i < scoreVector.size(); ++i) cerr << scoreVector[i] << " ";
|
||||
cerr << endl;
|
||||
|
||||
statistics->targetPhrase->SetScore(this, scoreVector);
|
||||
statistics->targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
|
||||
ret->Add(new TargetPhrase(*statistics->targetPhrase));
|
||||
}
|
||||
return ret;
|
||||
|
@ -246,7 +246,7 @@ bool RuleTableLoaderStandard::Load(FormatType format
|
||||
targetPhrase->SetSparseScore(&ruleTable, sparseString);
|
||||
}
|
||||
|
||||
targetPhrase->SetScore(&ruleTable, scoreVector);
|
||||
targetPhrase->GetScoreBreakdown().Assign(&ruleTable, scoreVector);
|
||||
targetPhrase->Evaluate();
|
||||
|
||||
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(ruleTable, targetPhrase->GetSourcePhrase(), *targetPhrase, sourceLHS);
|
||||
|
@ -242,7 +242,7 @@ namespace Moses
|
||||
std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),TransformScore);
|
||||
std::transform(scoreVector.begin(),scoreVector.end(),scoreVector.begin(),FloorScore);
|
||||
|
||||
targetPhrase->SetScore(this, scoreVector);
|
||||
targetPhrase->GetScoreBreakdown().Assign(this, scoreVector);
|
||||
targetPhrase->Evaluate();
|
||||
|
||||
TargetPhraseCollection &phraseColl = GetOrCreateTargetPhraseCollection(rootNode, sourcePhrase, *targetPhrase, sourceLHS);
|
||||
|
@ -200,8 +200,7 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceWord,s
|
||||
{
|
||||
const StaticData &staticData = StaticData::Instance();
|
||||
const UnknownWordPenaltyProducer *unknownWordPenaltyProducer = staticData.GetUnknownWordPenaltyProducer();
|
||||
vector<float> wordPenaltyScore(1, -1);
|
||||
vector<float> unknownScore(1, FloorScore(TransformScore(0)));
|
||||
float unknownScore = FloorScore(TransformScore(0));
|
||||
|
||||
// unknown word, add as trans opt
|
||||
FactorCollection &factorCollection = FactorCollection::Instance();
|
||||
@ -260,7 +259,7 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const Word &sourceWord,s
|
||||
|
||||
}
|
||||
|
||||
targetPhrase.SetScore(unknownWordPenaltyProducer, unknownScore);
|
||||
targetPhrase.GetScoreBreakdown().Assign(unknownWordPenaltyProducer, unknownScore);
|
||||
|
||||
if (inputScores != NULL) {
|
||||
targetPhrase.SetInputScore(*inputScores);
|
||||
|
Loading…
Reference in New Issue
Block a user