Пример #1
0
def predict(path):
    np.random.seed(42)
    tf.set_random_seed(42)
    config = Config.get_default_config(args)
    model = Model(config)
    predictor = InteractivePredictor(config, model, path)
    predictor.predict()
    model.close_session()
    args = parser.parse_args()

    replace_tokens = ["@R_%d@"%i for i in range(1, args.num_replace_tokens+1)]

    if args.debug:
        config = Config.get_debug_config(args)
    else:
        config = Config.get_default_config(args)

    # Composite training loss
    lamb = args.lamb
    print('Lamb :=' + str(lamb))

    model = Model(config, replace_tokens)
    print('Created model')

    if config.TRAIN_PATH:
        model.train(lamb=lamb)
    if config.TEST_PATH and not args.data_path:
        results, precision, recall, f1 = model.evaluate()
        print('Accuracy: ' + str(results))
        print('Precision: ' + str(precision) + ', recall: ' + str(recall) + ', F1: ' + str(f1))
    if args.predict:
        predictor = InteractivePredictor(config, model)
        predictor.predict()
    if args.adv_eval:
        model.adv_eval_batched()    
    if args.release and args.load_path:
        model.evaluate(release=True)
    model.close_session()
Пример #3
0
    tf.random.set_seed(args.seed)

    if args.debug:
        config = Config.get_debug_config(args)
        tf.config.experimental_run_functions_eagerly(True)
    else:
        config = Config.get_default_config(args)

    print('Created model')
    if config.TRAIN_PATH:
        model = ModelRunner(config)
        model.train()
    #if config.TEST_PATH and not args.data_path:
    #model = ModelRunner(config)
    #results, precision, recall, f1, rouge, bleu = model.evaluate('test')
    #print('Accuracy: ' + str(results))
    #print('Precision: ' + str(precision) + ', recall: ' + str(recall) + ', F1: ' + str(f1))
    #print('Rouge: ', rouge)
    #print('Bleu: ', bleu)
    if args.predict:
        model = ModelRunner(config)
        predictor = InteractivePredictor(config, model)
        paths = glob(args.predict)

        if args.shard:
            paths = [
                path for path in paths if path[args.predict.find('*') +
                                               1:].startswith(str(args.shard))
            ]
        predictor.predict(paths)