Beispiel #1
0
    # gpu
    gpu = torch.cuda.is_available()
    if gpu:
        print('The train will be using GPU.')
    else:
        print('The train will be using CPU.')
    print('CuDNN', torch.backends.cudnn.enabled)

    # config
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--config_file', type=str, default='./Config/config.ini')
    args = arg_parser.parse_args()
    config = Config(args.config_file)
    if gpu:
        config.add_args('Train', 'use_cuda', 'True')

    # data_loader
    sem_data_loader = ReadSenData(config)
    tra_sen_data, dev_sen_data = sem_data_loader.read_data()
    word_data_loader = ReadData(config)
    tra_data, dev_data = word_data_loader.read_data()

    # vocab
    if os.path.isfile(config.fact_word_vocab):
        tra_fact_word_vocab = read_pkl(config.fact_word_vocab)
        tra_fact_char_vocab = read_pkl(config.fact_char_vocab)
        if config.read_sen:
            tra_fact_sen_vocab = read_pkl(config.fact_sen_vocab)
    else:
        if not os.path.isdir(config.save_vocab_path):
Beispiel #2
0
    gpu = torch.cuda.is_available()
    if gpu:
        print('The train will be using GPU.')
    else:
        print('The train will be using CPU.')
    print('CuDNN', torch.backends.cudnn.enabled)

    # config
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument('--config_file',
                            type=str,
                            default='./Config/config.ini')
    args = arg_parser.parse_args()
    config = Config(args.config_file)
    if gpu:
        config.add_args('Train', 'use_cuda', 'True')
        config.add_args('Train', 'fp16', 'False')

    word_data_loader = ReadData(config)

    usual_tra_data_set, virus_tra_data_set, usual_dev_data_set, virus_dev_data_set, usual_vat_data, virus_vat_data \
        = word_data_loader.read_data(tokenizer)
    usual_eval_data, virus_eval_data = word_data_loader.read_eval_data(
        tokenizer)

    # vocab
    if os.path.isfile(config.fact_word_src_vocab):
        tag_vocab = read_pkl(config.fact_word_tag_vocab)
    else:
        if not os.path.isdir(config.save_vocab_path):
            os.makedirs(config.save_vocab_path)