Exemplo n.º 1
0
elif modelToUse == 7:
    print("Using model VII")
    rnOutput = modelBuilder.buildRN_VII_jl(objects, question)
elif modelToUse == 8 and layerCount >= 0:
    print("Using model VIII with " + str(layerCount) + " layers")
    rnOutput = modelBuilder.buildRN_VIII_jl(objects, question, layerCount)
else:
    print("Invalid model number specified: " + str(modelToUse))
    sys.exit(0)

#(answer, answerGates, answerForCorrectness) = modelBuilder.buildAnswerModel(rnOutput)
(answer, answerForCorrectness) = modelBuilder.buildAnswerModel(rnOutput)

(inputAnswer, loss, accum_ops, zero_ops, train_step, global_step_tensor,
 gradientsNorm,
 learningRate) = modelBuilder.buildOptimizer(answer,
                                             args.optimizer)  #, answerGates)

with tf.name_scope('testing'):
    #correct = tf.reduce_min(tf.cast(tf.equal(inputAnswer, tf.round(answer)), dtype=tf.float32), axis=1)#bad results since the max entries often don't achieve 0.5 so rounding doesnt work
    #correct = tf.cast(tf.equal(tf.argmax(inputAnswer, axis=1), tf.argmax(answer, axis=1)), dtype=tf.float32)#this is incorrect for multi-answer questions but gives better answers than rounding on single-answer questions -> TODO: find good solution for multi-answer questions
    #idea for better implementation of "correct"-variable: take argmax of answer1, answer2, answer3 each, also round answerGates and then calculate "answer" similar as in "buildModel()" and finally check tf.equal
    correct = tf.cast(tf.reduce_all(tf.equal(answerForCorrectness,
                                             inputAnswer),
                                    axis=1),
                      dtype=tf.float32)
    accuracy = tf.reduce_mean(correct)

saver = tf.train.Saver()


def checkTrainingAccuracy():
Exemplo n.º 2
0
    (rnOutput, isTraining) = modelBuilder.buildRN_VI(objects, question)
elif modelToUse == 7:
    print("Using model VII")
    (rnOutput, isTraining) = modelBuilder.buildRN_VII_jl(objects, question)
elif modelToUse == 8 and layerCount >= 0:
    print("Using model VIII with " + str(layerCount) + " layers")
    (rnOutput, isTraining) = modelBuilder.buildRN_VIII_jl(objects, inputContextLengths, question, layerCount)
else:
    print("Invalid model number specified: " + str(modelToUse))
    sys.exit(0)

#(answer, answerGates, answerForCorrectness) = modelBuilder.buildAnswerModel(rnOutput)
(answer, answerForCorrectness) = modelBuilder.buildAnswerModel(rnOutput)

#(inputAnswer, loss, optimizer_op, global_step_tensor, gradientsNorm, learningRate) = modelBuilder.buildOptimizer(answer, args.optimizer)#, answerGates)
(inputAnswer, loss, accum_ops, zero_ops, train_step, global_step_tensor, gradientsNorm, learningRate) = modelBuilder.buildOptimizer(answer, args.optimizer)#, answerGates)

with tf.name_scope('validation'):
    #correct = tf.reduce_min(tf.cast(tf.equal(inputAnswer, tf.round(answer)), dtype=tf.float32), axis=1)#bad results since the max entries often don't achieve 0.5 so rounding doesnt work
    #correct = tf.cast(tf.equal(tf.argmax(inputAnswer, axis=1), tf.argmax(answer, axis=1)), dtype=tf.float32)#this is incorrect for multi-answer questions but gives better answers than rounding on single-answer questions -> TODO: find good solution for multi-answer questions
    #idea for better implementation of "correct"-variable: take argmax of answer1, answer2, answer3 each, also round answerGates and then calculate "answer" similar as in "buildModel()" and finally check tf.equal
    correct = tf.cast(tf.reduce_all(tf.equal(answerForCorrectness, inputAnswer), axis=1), dtype=tf.float32)
    accuracy = tf.reduce_mean(correct)
    total_acc_placeholder = tf.placeholder(tf.float32, shape=())
    task_acc_placeholders = {}
    for task_name in validationData:
        task_acc_placeholders[task_name] = tf.placeholder(tf.float32, shape=())
    training_acc_placeholder = tf.placeholder(tf.float32, shape=())

#prepare tensorboard summaries
loss_summary = tf.summary.scalar('loss', loss)