mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-09-20 07:42:21 +03:00
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:
parent
6b4a0b442b
commit
f29d58e3f3
@ -433,7 +433,7 @@ int main(int argc, char** argv) {
|
||||
vector<size_t> ref_ids;
|
||||
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
|
||||
!= shard.end(); ++batchPosition) {
|
||||
string& input = inputSentences[*sid];
|
||||
@ -528,9 +528,9 @@ int main(int argc, char** argv) {
|
||||
|
||||
// get 1best model results with old weights
|
||||
vector<float> bestModelOld;
|
||||
if (actualBatchSize == 1) {
|
||||
string& input = inputSentences[*current_sid];
|
||||
bestModelOld = decoder->getBleuAndScore(input, *current_sid, 0.0, distinctNbest);
|
||||
for (size_t i = 0; i < actualBatchSize; ++i) {
|
||||
string& input = inputSentences[*current_sid_start + i];
|
||||
bestModelOld = decoder->getBleuAndScore(input, *current_sid_start + i, 0.0, distinctNbest);
|
||||
decoder->cleanup();
|
||||
}
|
||||
|
||||
@ -550,7 +550,7 @@ int main(int argc, char** argv) {
|
||||
ScoreComponentCollection oldWeights(mosesWeights);
|
||||
vector<int> update_status = optimiser->updateWeights(mosesWeights, featureValues,
|
||||
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) {
|
||||
cerr << "Rank " << rank << ", no update for batch" << endl;
|
||||
@ -594,11 +594,11 @@ int main(int argc, char** argv) {
|
||||
weightDifference.MinusEquals(oldWeights);
|
||||
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;
|
||||
if (actualBatchSize == 1) {
|
||||
string& input = inputSentences[*current_sid];
|
||||
bestModelNew = decoder->getBleuAndScore(input, *current_sid, 0.0, distinctNbest);
|
||||
for (size_t i = 0; i < actualBatchSize; ++i) {
|
||||
string& input = inputSentences[*current_sid_start + i];
|
||||
bestModelNew = decoder->getBleuAndScore(input, *current_sid_start + i, 0.0, distinctNbest);
|
||||
decoder->cleanup();
|
||||
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;
|
||||
@ -774,12 +774,15 @@ int main(int argc, char** argv) {
|
||||
if (stop_optimal) {
|
||||
if (epoch > 0) {
|
||||
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 {
|
||||
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;
|
||||
sumStillViolatedConstraints_lastEpoch = sumStillViolatedConstraints;
|
||||
|
@ -12,7 +12,7 @@ vector<int> MiraOptimiser::updateWeights(ScoreComponentCollection& currWeights,
|
||||
const vector<std::vector<float> >& bleuScores, const vector<
|
||||
ScoreComponentCollection>& oracleFeatureValues,
|
||||
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,
|
||||
bool controlUpdates) {
|
||||
|
||||
@ -202,7 +202,7 @@ vector<int> MiraOptimiser::updateWeights(ScoreComponentCollection& currWeights,
|
||||
summedUpdate.PlusEquals(featureValueDiffs[k]);
|
||||
}
|
||||
} 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);
|
||||
status[0] = 1;
|
||||
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) {
|
||||
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) {
|
||||
vector<int> statusPlus(3);
|
||||
statusPlus[0] = -1;
|
||||
|
@ -39,6 +39,7 @@ namespace Mira {
|
||||
float learning_rate,
|
||||
float max_sentence_update,
|
||||
size_t rank,
|
||||
size_t epoch,
|
||||
int updates_per_epoch,
|
||||
bool controlUpdates) = 0;
|
||||
};
|
||||
@ -55,6 +56,7 @@ namespace Mira {
|
||||
float learning_rate,
|
||||
float max_sentence_update,
|
||||
size_t rank,
|
||||
size_t epoch,
|
||||
int updates_per_epoch,
|
||||
bool controlUpdates);
|
||||
};
|
||||
@ -90,6 +92,7 @@ namespace Mira {
|
||||
float learning_rate,
|
||||
float max_sentence_update,
|
||||
size_t rank,
|
||||
size_t epoch,
|
||||
int updates_per_epoch,
|
||||
bool controlUpdates);
|
||||
|
||||
|
@ -34,6 +34,7 @@ vector<int> Perceptron::updateWeights(ScoreComponentCollection& currWeights,
|
||||
float learning_rate,
|
||||
float max_sentence_update,
|
||||
size_t rank,
|
||||
size_t epoch,
|
||||
int updates_per_epoch,
|
||||
bool controlUpdates)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user