def val_step(inp, tar, epoch, inp_shape, tar_shape, batch, create_summ):
    tar_inp = tar[:, :-1]
    tar_real = tar[:, 1:]
    enc_padding_mask, combined_mask, dec_padding_mask = create_masks(
        inp, tar_inp)
    predictions, attention_weights, dec_output = transformer(
        inp, tar_inp, False, enc_padding_mask, combined_mask, dec_padding_mask)
    if config.copy_gen:
        predictions = pointer_generator(dec_output,
                                        predictions,
                                        attention_weights,
                                        inp,
                                        inp_shape,
                                        tar_shape,
                                        batch,
                                        training=False)
    loss = loss_function(tar_real, predictions)
    validation_loss(loss)
    validation_accuracy(tar_real, predictions)
    if create_summ:
        rouge, bert = tf_write_summary(tar_real, predictions, inp[:, 1:],
                                       epoch)
    else:
        rouge, bert = (1.0, 1.0)
    return (rouge, bert)
Esempio n. 2
0
 def val_step(input_ids,
              input_mask,
              input_segment_ids,
              target_ids_,
              target_mask,
              target_segment_ids,
              target_ids,
              draft_mask,
              refine_mask,
              step,
              create_summ):
   (draft_predictions, draft_attention_weights,
    refine_predictions, refine_attention_weights) = model(
                                                          input_ids, input_mask, input_segment_ids,
                                                          target_ids_, target_mask, target_segment_ids,
                                                          False
                                                          )
   draft_summary_loss = loss_function(target_ids[:, 1:, :], draft_predictions, draft_mask)
   refine_summary_loss = loss_function(target_ids[:, :-1, :], refine_predictions, refine_mask)
   loss = draft_summary_loss + refine_summary_loss
   loss = tf.reduce_mean(loss)
   validation_loss(loss)
   validation_accuracy(target_ids_[:, :-1], refine_predictions)
   if create_summ:
     rouge, bert = tf_write_summary(target_ids_[:, :-1], refine_predictions, step)
   else:
     rouge, bert = (1.0, 1.0)
   return (rouge, bert)
Esempio n. 3
0
def val_step(inp, tar, epoch, create_summ):

    draft_predictions, draft_attention_weights, draft_dec_output = draft_summary_model(
        inp, tar, training=False)
    refine_predictions, refine_attention_weights, refine_dec_output = refine_summary_model(
        inp, tar, training=False)
    draft_summary_loss = loss_function(tar[0][:, 1:, :], draft_predictions)
    refine_summary_loss = loss_function(tar[0][:, :-1, :], refine_predictions)
    loss = draft_summary_loss + refine_summary_loss
    validation_loss(loss)
    validation_accuracy(tar_real, predictions)
    if create_summ:
        rouge, bert = tf_write_summary(tar_real, predictions, inp[:, 1:],
                                       epoch)
    else:
        rouge, bert = (1.0, 1.0)
    return (rouge, bert)
Esempio n. 4
0
def val_step(input_ids, target_ids_, step, create_summ):
    validation_accuracy.reset_states()
    from decode_text import predict_using_sampling
    (preds_draft_summary, _, refine_predictions,
     _) = predict_using_sampling(input_ids,
                                 refine_decoder_sampling_type='greedy',
                                 temperature=0.9,
                                 p=0.8,
                                 k=7)

    validation_accuracy(
        target_ids_[:, 1:],
        tf.one_hot(refine_predictions[:, 1:], depth=config.input_vocab_size))
    if create_summ:
        rouge, bert = tf_write_summary(target_ids_[:, 1:],
                                       refine_predictions[:, 1:], step)
    else:
        rouge, bert = (1.0, 1.0)
    return (rouge, bert)
def val_step(inp, tar, epoch, create_summ):
  tar_inp = tar[:, :-1]
  tar_real = tar[:, 1:]
  enc_padding_mask, combined_mask, dec_padding_mask = create_masks(inp, tar_inp)
  predictions, attention_weights, dec_output = model(
                                                     inp, 
                                                     tar_inp, 
                                                     enc_padding_mask, 
                                                     combined_mask, 
                                                     dec_padding_mask,
                                                     training=False
                                                     )
  loss = loss_function(tar_real, predictions)
  validation_loss(loss)
  validation_accuracy(tar_real, predictions)
  if create_summ: 
    rouge, bert = tf_write_summary(tar_real, predictions, inp[:, 1:], epoch)  
  else: 
    rouge, bert = (1.0, 1.0)  
  return (rouge, bert)