Esempio n. 1
0
            except:
                step = 0
            test_abs(args, device_id, cp, step)
        elif (args.mode == 'test_text'):
            cp = args.test_from
            try:
                step = int(cp.split('.')[-2].split('_')[-1])
            except:
                step = 0
                test_text_abs(args, device_id, cp, step)

    elif (args.task == 'ext'):
        if (args.mode == 'train'):
            train_ext(args, device_id)
        elif (args.mode == 'validate'):
            validate_ext(args, device_id)
        if (args.mode == 'test'):
            cp = args.test_from
            try:
                step = int(cp.split('.')[-2].split('_')[-1])
            except:
                step = 0
            test_ext(args, device_id, cp, step)
        elif (args.mode == 'test_text'):
            cp = args.test_from
            try:
                step = int(cp.split('.')[-2].split('_')[-1])
            except:
                step = 0
                test_text_abs(args, device_id, cp, step)
Esempio n. 2
0
    elif args.mode == 'test':
        checkpoint = args.load_model

        # Print or save summaries and probas for test mode
        logging.info("Processing files...")
        with open('../results/patents_analysis.csv', mode='w') as file:
            writer = csv.writer(file,
                                delimiter='?',
                                quotechar='"',
                                quoting=csv.QUOTE_MINIMAL)
            writer.writerow([
                'Ref patent', 'Domain', 'Probability of contradiction',
                'First part Contradiction', 'Second part Contradiction',
                'Context'
            ])
            for ref_patents, summaries, output_probas, prediction_contradiction, str_context in test_ext(
                    args, device_id, checkpoint, 0):
                for ref_patent, summary, output_proba, prediction_c, context in zip(
                        ref_patents, summaries, output_probas,
                        prediction_contradiction, str_context):

                    # print(summary)
                    # Get patents domain if possible
                    try:
                        with open(
                                '../data_patents/input_data/test_directory/' +
                                ref_patent + '/' + ref_patent + '.DOMAIN',
                                mode='r') as domain_f:
                            name_domain = domain_f.read()
                    except:
                        name_domain = 'unknown'
Esempio n. 3
0
                step = 0
            test_abs(args, device_id, cp, step)
        elif (args.mode == 'test_text'):
            cp = args.test_from
            try:
                step = int(cp.split('.')[-2].split('_')[-1])
            except:
                step = 0
                test_text_abs(args, device_id, cp, step)

    elif (args.task == 'ext'):
        if (args.mode == 'train'):
            # print('joint: ' + str(args.section_prediction))
            train_ext(args, device_id, args.section_prediction)
        elif (args.mode == 'validate'):
            validate_ext(args, device_id)
        if (args.mode == 'test'):
            cp = args.test_from
            try:
                step = int(cp.split('.')[-2].split('_')[-1])
            except:
                step = 0
            test_ext(args, device_id, cp, step, args.section_prediction)
        elif (args.mode == 'test_text'):
            cp = args.test_from
            try:
                step = int(cp.split('.')[-2].split('_')[-1])
            except:
                step = 0
                test_text_abs(args, device_id, cp, step)
Esempio n. 4
0
 def run(args, hpspace):
     if (args.task == 'abs'):
         if (args.mode == 'train'):
             if (args.hyperopt):
                 t = time.time()
                 newT = str(t).split(".")
                 args.model_path = "../models/" + newT[0]
                 args.log_file = "../logs/abs_bert_abs_" + newT[0]
                 args.lr_bert = hpspace['lr_bert']
                 args.lr_dec = hpspace['lr_dec']
                 args.accum_count = int(hpspace['accum_count'])
                 args.beta1 = hpspace['beta1']
                 args.beta2 = hpspace['beta2']
                 args.visible_gpus = '0'
                 args.bert_model = '..temp/bert-base-danish-uncased-v2'
                 args.vocab = '..temp/bert-base-danish-uncased-v2'
             train_stats = train_abs(args, device_id)
             x = train_stats.x
             ppl = train_stats.perplexity
             acc = train_stats.acc
             print(x)
             return {
                 'loss': x,
                 'eval_time': time.time(),
                 'status': STATUS_OK,
                 'other_stuff': {
                     'ppl': ppl,
                     'acc': acc
                 }
             }
         elif (args.mode == 'validate'):
             validate_abs(args, device_id)
         elif (args.mode == 'lead'):
             baseline(args, cal_lead=True)
         elif (args.mode == 'oracle'):
             baseline(args, cal_oracle=True)
         if (args.mode == 'test'):
             cp = args.test_from
             try:
                 step = int(cp.split('.')[-2].split('_')[-1])
             except:
                 step = 0
             test_abs(args, device_id, cp, step)
         elif (args.mode == 'test_text'):
             cp = args.test_from
             try:
                 step = int(cp.split('.')[-2].split('_')[-1])
             except:
                 step = 0
                 test_text_abs(args, device_id, cp, step)
     elif (args.task == 'ext'):
         if (args.mode == 'train'):
             train_ext(args, device_id)
         elif (args.mode == 'validate'):
             validate_ext(args, device_id)
         if (args.mode == 'test'):
             cp = args.test_from
             try:
                 step = int(cp.split('.')[-2].split('_')[-1])
             except:
                 step = 0
             test_ext(args, device_id, cp, step)
         elif (args.mode == 'test_text'):
             cp = args.test_from
             try:
                 step = int(cp.split('.')[-2].split('_')[-1])
             except:
                 step = 0
                 test_text_abs(args, device_id, cp, step)
     if (args.mode == "sent_label"):
         step = 0
         sent_label_ext(args, device_id)