本文整理汇总了C++中Evaluator::Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C++ Evaluator::Evaluate方法的具体用法?C++ Evaluator::Evaluate怎么用?C++ Evaluator::Evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Evaluator
的用法示例。
在下文中一共展示了Evaluator::Evaluate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitializeBlob
void RecurrentNeuralNetworkPartOfSpeechTagger<F>::Train(
const std::vector<TaggedSentence> &tagged_sentences,
F learning_rate,
F momentum,
F lambda_1,
F lambda_2,
int iterations,
Evaluator<F> &evaluator,
const std::vector<TaggedSentence> &validation_sentences,
const std::unordered_set<std::string> &training_vocabulary) {
// InitializeBlob(uniform_symmetric, generator, &recurrent_state_input);
InitializeBlob(uniform_symmetric, generator, &classify_weights);
InitializeBlob(uniform_symmetric, generator, &combine_weights);
std::uniform_int_distribution<int> uniform(0, tagged_sentences.size() - 1);
constexpr auto minibatch_size = 100;
std::cout << "Training... " << std::endl << std::endl;
for (auto i = 0; i < iterations; ++i) {
std::cout << "Evaluating on validation data... ";
std::cout.flush();
auto validation_report = evaluator.Evaluate(
*this, validation_sentences, training_vocabulary);
std::cout << "Done." << std::endl;
std::cout << validation_report << std::endl<< std::endl;
std::cout << "Starting iteration " << i << "... " << std::endl << std::endl;
for (auto j = 0; j < tagged_sentences.size(); ++j) {
// auto u = uniform(generator);
auto u = j;
ForwardBackwardCpu(tagged_sentences.at(u));
classify_weights.ClipGradient(tagged_sentences.at(u).size());
classify_bias.ClipGradient(tagged_sentences.at(u).size());
combine_weights.ClipGradient(tagged_sentences.at(u).size());
combine_bias.ClipGradient(tagged_sentences.at(u).size());
classify_weights.L1Regularize(lambda_1);
classify_bias.L1Regularize(lambda_1);
combine_weights.L1Regularize(lambda_1);
combine_bias.L1Regularize(lambda_1);
auto magnitude = sqrt(classify_weights.values.SquareMagnitude()
+ classify_weights.values.SquareMagnitude()
+ combine_weights.values.SquareMagnitude()
+ combine_bias.values.SquareMagnitude());
classify_weights.L2Regularize(lambda_2, magnitude);
classify_bias.L2Regularize(lambda_2, magnitude);
combine_weights.L2Regularize(lambda_2, magnitude);
combine_bias.L2Regularize(lambda_2, magnitude);
// auto difference_magnitude = sqrt(classify_weights.differences.SquareMagnitude()
// + classify_weights.differences.SquareMagnitude()
// + combine_weights.differences.SquareMagnitude()
// + combine_bias.differences.SquareMagnitude());
// classify_weights.ClipGradient(difference_magnitude);
// classify_bias.ClipGradient(difference_magnitude);
// combine_weights.ClipGradient(difference_magnitude);
// combine_bias.ClipGradient(difference_magnitude);
// const auto modified_learning_rate = learning_rate * pow(F(0.1), i / 2.0);
const auto modified_learning_rate = learning_rate;
classify_weights.UpdateMomentum(modified_learning_rate, momentum);
classify_bias.UpdateMomentum(modified_learning_rate, momentum);
combine_weights.UpdateMomentum(modified_learning_rate, momentum);
combine_bias.UpdateMomentum(modified_learning_rate, momentum);
constexpr auto kAdaDeltaMemory = F(0.95);
// classify_weights.UpdateAdaDelta(modified_learning_rate, kAdaDeltaMemory);
// classify_bias.UpdateAdaDelta(modified_learning_rate, kAdaDeltaMemory);
// combine_weights.UpdateAdaDelta(modified_learning_rate, kAdaDeltaMemory);
// combine_bias.UpdateAdaDelta(modified_learning_rate, kAdaDeltaMemory);
// classify_weights.UpdateAdaGrad(modified_learning_rate);
// classify_bias.UpdateAdaGrad(modified_learning_rate);
// combine_weights.UpdateAdaGrad(modified_learning_rate);
// combine_bias.UpdateAdaGrad(modified_learning_rate);
classify_weights.differences.Reset();
classify_bias.differences.Reset();
combine_weights.differences.Reset();
combine_bias.differences.Reset();
// if (j > 0 && j % 100 == 0) {
// std::cout << "Finished " << j << " sentences." << std::endl;
// }
if (j > 0 && j + 1 < tagged_sentences.size() && j % 1000 == 0) {
// std::cout << std::endl << "Evaluating on validation data... ";
// std::cout.flush();
auto validation_report = evaluator.Evaluate(
*this, validation_sentences, training_vocabulary);
std::cout << "Done." << std::endl;
std::cout << validation_report << std::endl << std::endl;
//.........这里部分代码省略.........