fix scaling correction.. (hopefully)

This commit is contained in:
Eva Hasler 2012-01-31 18:14:28 +00:00
parent 1c1c3ea8eb
commit 960c60c9c6
3 changed files with 20 additions and 9 deletions

View File

@ -879,7 +879,8 @@ int main(int argc, char** argv) {
if (correctScaling && epoch == 0) {
float averageRatio = ((MiraOptimiser*) optimiser)->getSumRatios();
averageRatio /= numberOfUpdatesThisEpoch;
size_t ratioCount = ((MiraOptimiser*) optimiser)->getRatioCount();
averageRatio /= ratioCount;
cerr << "Rank " << rank << ", epoch " << epoch << ", average ratio: " << averageRatio << endl;
float correctionFactor = 0.9;
float mixedAverageRatio = 0;
@ -894,11 +895,13 @@ int main(int argc, char** argv) {
MPI_Reduce(sendbuf_float, recvbuf_float, 1, MPI_FLOAT, MPI_SUM, 0, world);
mixedAverageRatio = recvbuf_float[0];
if (rank == 0) {
mixedAverageRatio /= size;
mixedAverageRatio *= correctionFactor;
mpi::broadcast(world, mixedAverageRatio, 0);
}
if (rank == 0) {
mixedAverageRatio /= size;
cerr << "Mixed average ratio: " << mixedAverageRatio << endl;
mixedAverageRatio *= correctionFactor;
cerr << "Mixed average ratio corrected: " << mixedAverageRatio << endl;
mpi::broadcast(world, mixedAverageRatio, 0);
}
#endif
#ifndef MPI_ENABLE
mixedAverageRatio = averageRatio;

View File

@ -345,14 +345,16 @@ size_t MiraOptimiser::updateWeightsAnalytically(
float loss = bleuScoreHope - bleuScoreFear;
float diff = 0;
float ratio = (modelScoreDiff == 0) ? 0 : loss / modelScoreDiff;
cerr << "Rank " << rank << ", epoch " << epoch << ", ratio model/loss: " << ratio << endl;
cerr << "Rank " << rank << ", epoch " << epoch << ", ratio loss/model: " << ratio << endl;
if (loss > (modelScoreDiff + m_margin_slack)) {
diff = loss - (modelScoreDiff + m_margin_slack);
}
cerr << "Rank " << rank << ", epoch " << epoch << ", constraint: " << modelScoreDiff << " + " << m_margin_slack << " >= " << loss << " (current violation: " << diff << ")" << endl;
if (epoch == 0)
if (epoch == 0 && modelScoreDiff > 0) {
m_sum_ratios += ratio;
m_count_ratios++;
}
if (diff > epsilon) {
// constraint violated

View File

@ -68,7 +68,8 @@ namespace Mira {
m_scale_margin(scale_margin),
m_scale_update(scale_update),
m_margin_slack(margin_slack),
m_sum_ratios(0) { }
m_sum_ratios(0),
m_count_ratios(0) { }
size_t updateWeights(Moses::ScoreComponentCollection& currWeights,
Moses::ScoreComponentCollection& weightUpdate,
@ -111,6 +112,10 @@ namespace Mira {
return m_sum_ratios;
}
size_t getRatioCount() {
return m_count_ratios;
}
private:
// add only violated constraints to the optimisation problem
@ -129,6 +134,7 @@ namespace Mira {
// collect (loss diff/model score diff) ratios from first epoch
float m_sum_ratios;
size_t m_count_ratios;
};
}