bleu before and after opt. for batch, print error of constraints

git-svn-id: http://svn.statmt.org/repository/mira@3871 cc96ff50-19ce-11e0-b349-13d7f0bd23df
This commit is contained in:
ehasler 2011-04-11 12:22:19 +00:00 committed by Ondrej Bojar
parent 6b4a0b442b
commit f29d58e3f3
4 changed files with 22 additions and 15 deletions

View File

@ -433,7 +433,7 @@ int main(int argc, char** argv) {
vector<size_t> ref_ids; vector<size_t> ref_ids;
size_t actualBatchSize = 0; size_t actualBatchSize = 0;
vector<size_t>::const_iterator current_sid = sid; vector<size_t>::const_iterator current_sid_start = sid;
for (size_t batchPosition = 0; batchPosition < batchSize && sid for (size_t batchPosition = 0; batchPosition < batchSize && sid
!= shard.end(); ++batchPosition) { != shard.end(); ++batchPosition) {
string& input = inputSentences[*sid]; string& input = inputSentences[*sid];
@ -528,9 +528,9 @@ int main(int argc, char** argv) {
// get 1best model results with old weights // get 1best model results with old weights
vector<float> bestModelOld; vector<float> bestModelOld;
if (actualBatchSize == 1) { for (size_t i = 0; i < actualBatchSize; ++i) {
string& input = inputSentences[*current_sid]; string& input = inputSentences[*current_sid_start + i];
bestModelOld = decoder->getBleuAndScore(input, *current_sid, 0.0, distinctNbest); bestModelOld = decoder->getBleuAndScore(input, *current_sid_start + i, 0.0, distinctNbest);
decoder->cleanup(); decoder->cleanup();
} }
@ -550,7 +550,7 @@ int main(int argc, char** argv) {
ScoreComponentCollection oldWeights(mosesWeights); ScoreComponentCollection oldWeights(mosesWeights);
vector<int> update_status = optimiser->updateWeights(mosesWeights, featureValues, vector<int> update_status = optimiser->updateWeights(mosesWeights, featureValues,
losses, bleuScores, oracleFeatureValues, oracleBleuScores, ref_ids, losses, bleuScores, oracleFeatureValues, oracleBleuScores, ref_ids,
learning_rate, max_sentence_update, rank, updates_per_epoch, controlUpdates); learning_rate, max_sentence_update, rank, epoch, updates_per_epoch, controlUpdates);
if (update_status[0] == 1) { if (update_status[0] == 1) {
cerr << "Rank " << rank << ", no update for batch" << endl; cerr << "Rank " << rank << ", no update for batch" << endl;
@ -594,11 +594,11 @@ int main(int argc, char** argv) {
weightDifference.MinusEquals(oldWeights); weightDifference.MinusEquals(oldWeights);
cerr << "Rank " << rank << ", weight difference: " << weightDifference << endl; cerr << "Rank " << rank << ", weight difference: " << weightDifference << endl;
// get 1best model results with new weights // get 1best model results with new weights (for each sentence in batch)
vector<float> bestModelNew; vector<float> bestModelNew;
if (actualBatchSize == 1) { for (size_t i = 0; i < actualBatchSize; ++i) {
string& input = inputSentences[*current_sid]; string& input = inputSentences[*current_sid_start + i];
bestModelNew = decoder->getBleuAndScore(input, *current_sid, 0.0, distinctNbest); bestModelNew = decoder->getBleuAndScore(input, *current_sid_start + i, 0.0, distinctNbest);
decoder->cleanup(); decoder->cleanup();
cerr << "Rank " << rank << ", epoch " << epoch << ", 1best model bleu, old: " << bestModelOld[0] << ", new: " << bestModelNew[0] << endl; cerr << "Rank " << rank << ", epoch " << epoch << ", 1best model bleu, old: " << bestModelOld[0] << ", new: " << bestModelNew[0] << endl;
cerr << "Rank " << rank << ", epoch " << epoch << ", 1best model score, old: " << bestModelOld[1] << ", new: " << bestModelNew[1] << endl; cerr << "Rank " << rank << ", epoch " << epoch << ", 1best model score, old: " << bestModelOld[1] << ", new: " << bestModelNew[1] << endl;
@ -774,12 +774,15 @@ int main(int argc, char** argv) {
if (stop_optimal) { if (stop_optimal) {
if (epoch > 0) { if (epoch > 0) {
if (sumConstraintChangeAbs_lastEpoch == sumConstraintChangeAbs && sumStillViolatedConstraints_lastEpoch == sumStillViolatedConstraints) { if (sumConstraintChangeAbs_lastEpoch == sumConstraintChangeAbs && sumStillViolatedConstraints_lastEpoch == sumStillViolatedConstraints) {
cerr << "Rank " << rank << ", sum of violated constraints and constraint changes has stayed the same: " << sumStillViolatedConstraints << ", " << sumConstraintChangeAbs << endl; cerr << "Rank " << rank << ", epoch " << epoch << ", sum of violated constraints and constraint changes has stayed the same: " << sumStillViolatedConstraints << ", " << sumConstraintChangeAbs << endl;
} }
else { else {
cerr << "Rank " << rank << ", sum of violated constraints: " << sumStillViolatedConstraints << ", sum of constraint changes " << sumConstraintChangeAbs << endl; cerr << "Rank " << rank << ", epoch " << epoch << ", sum of violated constraints: " << sumStillViolatedConstraints << ", sum of constraint changes " << sumConstraintChangeAbs << endl;
} }
} }
else {
cerr << "Rank " << rank << ", epoch " << epoch << ", sum of violated constraints: " << sumStillViolatedConstraints << endl;
}
sumConstraintChangeAbs_lastEpoch = sumConstraintChangeAbs; sumConstraintChangeAbs_lastEpoch = sumConstraintChangeAbs;
sumStillViolatedConstraints_lastEpoch = sumStillViolatedConstraints; sumStillViolatedConstraints_lastEpoch = sumStillViolatedConstraints;

View File

@ -12,7 +12,7 @@ vector<int> MiraOptimiser::updateWeights(ScoreComponentCollection& currWeights,
const vector<std::vector<float> >& bleuScores, const vector< const vector<std::vector<float> >& bleuScores, const vector<
ScoreComponentCollection>& oracleFeatureValues, ScoreComponentCollection>& oracleFeatureValues,
const vector<float> oracleBleuScores, const vector<size_t> sentenceIds, const vector<float> oracleBleuScores, const vector<size_t> sentenceIds,
float learning_rate, float max_sentence_update, size_t rank, float learning_rate, float max_sentence_update, size_t rank, size_t epoch,
int updates_per_epoch, int updates_per_epoch,
bool controlUpdates) { bool controlUpdates) {
@ -202,7 +202,7 @@ vector<int> MiraOptimiser::updateWeights(ScoreComponentCollection& currWeights,
summedUpdate.PlusEquals(featureValueDiffs[k]); summedUpdate.PlusEquals(featureValueDiffs[k]);
} }
} else { } else {
cerr << "Rank " << rank << ", check, no constraint violated for this batch" << endl; cerr << "Rank " << rank << ", epoch " << epoch << ", check, no constraint violated for this batch" << endl;
vector<int> status(3); vector<int> status(3);
status[0] = 1; status[0] = 1;
status[1] = 0; status[1] = 0;
@ -235,10 +235,10 @@ vector<int> MiraOptimiser::updateWeights(ScoreComponentCollection& currWeights,
} }
} }
} }
cerr << "Rank " << rank << ", check, violated constraint before: " << violatedConstraintsBefore << ", after: " << violatedConstraintsAfter << ", change: " << violatedConstraintsBefore - violatedConstraintsAfter << endl; cerr << "Rank " << rank << ", epoch " << epoch << ", check, violated constraint before: " << violatedConstraintsBefore << ", after: " << violatedConstraintsAfter << ", change: " << violatedConstraintsBefore - violatedConstraintsAfter << endl;
cerr << "Rank " << rank << ", epoch " << epoch << ", check, error before: " << oldDistanceFromOptimum << ", after: " << newDistanceFromOptimum << ", change: " << oldDistanceFromOptimum - newDistanceFromOptimum << endl;
if (violatedConstraintsAfter > 0) { if (violatedConstraintsAfter > 0) {
float distanceChange = oldDistanceFromOptimum - newDistanceFromOptimum; float distanceChange = oldDistanceFromOptimum - newDistanceFromOptimum;
cerr << "Rank " << rank << ", check, there are still violated constraints, the distance change is: " << distanceChange << endl;
if (controlUpdates && (violatedConstraintsBefore - violatedConstraintsAfter) < 0 && distanceChange < 0) { if (controlUpdates && (violatedConstraintsBefore - violatedConstraintsAfter) < 0 && distanceChange < 0) {
vector<int> statusPlus(3); vector<int> statusPlus(3);
statusPlus[0] = -1; statusPlus[0] = -1;

View File

@ -39,6 +39,7 @@ namespace Mira {
float learning_rate, float learning_rate,
float max_sentence_update, float max_sentence_update,
size_t rank, size_t rank,
size_t epoch,
int updates_per_epoch, int updates_per_epoch,
bool controlUpdates) = 0; bool controlUpdates) = 0;
}; };
@ -55,6 +56,7 @@ namespace Mira {
float learning_rate, float learning_rate,
float max_sentence_update, float max_sentence_update,
size_t rank, size_t rank,
size_t epoch,
int updates_per_epoch, int updates_per_epoch,
bool controlUpdates); bool controlUpdates);
}; };
@ -90,6 +92,7 @@ namespace Mira {
float learning_rate, float learning_rate,
float max_sentence_update, float max_sentence_update,
size_t rank, size_t rank,
size_t epoch,
int updates_per_epoch, int updates_per_epoch,
bool controlUpdates); bool controlUpdates);

View File

@ -34,6 +34,7 @@ vector<int> Perceptron::updateWeights(ScoreComponentCollection& currWeights,
float learning_rate, float learning_rate,
float max_sentence_update, float max_sentence_update,
size_t rank, size_t rank,
size_t epoch,
int updates_per_epoch, int updates_per_epoch,
bool controlUpdates) bool controlUpdates)
{ {