Esempio n. 1
0
def run(config_file):
    # 命令行解析器
    args = argparse.ArgumentParser(description='text classification')

    # 添加命令:配置、重启、计算
    args.add_argument('-c',
                      '--config',
                      default=config_file,
                      type=str,
                      help='config file path (default: None)')
    args.add_argument('-r',
                      '--resume',
                      default=None,
                      type=str,
                      help='path to latest checkpoint (default: None)')
    args.add_argument('-d',
                      '--device',
                      default='0,1',
                      type=str,
                      help='indices of GPUs to enable (default: all)')

    # 客户参数:可修改的配置
    CustomArgs = collections.namedtuple('CustomArgs', 'flags type target')
    # 添加客户参数:学习率、批量长度
    options = [
        CustomArgs(['--lr', '--learning_rate'],
                   type=float,
                   target='optimizer;args;lr'),
        CustomArgs(['--bs', '--batch_size'],
                   type=int,
                   target='data_process;args;batch_size')
    ]
    # 配置解析器
    config = ConfigParser.from_args(args, options)
    # 打印训练的模型类型
    print(config.config['model_arch']['type'].lower())

    # 训练
    if 'bert' in config.config['model_arch']['type'].lower():
        main(config, use_transformers=True)
    else:
        main(config, use_transformers=False)
Esempio n. 2
0
def run(config_file, model_path, text_list):
    args = argparse.ArgumentParser(description='text classification')

    # 配置文件、模型路径、计算代理
    args.add_argument('-c', '--config', default=config_file, type=str, help='config file path (default: None)')
    # default=model_path
    args.add_argument('-r', '--resume', default=model_path, type=str, help='path to latest checkpoint (default: None)')
    # default='0',
    args.add_argument('-d', '--device', default='0', type=str, help='indices of GPUs to enable (default: all)')

    CustomArgs = collections.namedtuple('CustomArgs', 'flags type target')
    options = [
        CustomArgs(['--lr', '--learning_rate'], type=float, target='optimizer;args;lr'),
        CustomArgs(['--bs', '--batch_size'], type=int, target='data_process;args;batch_size')
    ]
    config = ConfigParser.from_args(args, options)
    print(config.config['model_arch']['type'].lower())

    if 'bert' in config.config['model_arch']['type'].lower():
        main(config, use_transformers=True, text_list=text_list)
    else:
        main(config, use_transformers=False, text_list=text_list)
Esempio n. 3
0
        help='path to the directory where parsed documents are saved'
        'in case parsed files exist here, KNP is skipped')
    parser.add_argument('--export-dir',
                        default=None,
                        type=str,
                        help='directory where analysis result is exported')
    parser.add_argument('-tab',
                        '--tab',
                        action='store_true',
                        default=False,
                        help='whether to output details')
    parser.add_argument(
        '--remote-knp',
        action='store_true',
        default=False,
        help='Use KNP running on remote host. '
        'Make sure you specify host address and port in analyzer/config.ini')
    parser.add_argument(
        '--skip-untagged',
        action='store_true',
        default=False,
        help='If set, do not export documents which failed to be analyzed')
    parser.add_argument(
        '--rel-only',
        action='store_true',
        default=False,
        help='If set, do not add <述語項構造> tag besides <rel> tag to system output'
    )
    parsed_args = parser.parse_args()
    main(ConfigParser.from_args(parsed_args, run_id=''), parsed_args)
Esempio n. 4
0
    args.add_argument('-c',
                      '--config',
                      default=None,
                      type=str,
                      help='config file path (default: None)')
    args.add_argument('-r',
                      '--resume',
                      default=None,
                      type=str,
                      help='path to latest checkpoint (default: None)')

    # custom cli options to modify configuration from default values given in json file.
    CustomArgs = collections.namedtuple('CustomArgs', 'flags type target')
    options = [
        CustomArgs(['-n', '--name'], type=str, target='name'),
        CustomArgs(['--lr', '--learning_rate'],
                   type=float,
                   target='optimizer;args;lr'),
        CustomArgs(['--bs', '--batch_size'],
                   type=int,
                   target='dataloader;args;batch_size'),
        CustomArgs(['--u2w', '--utt2wav_val'],
                   type=str,
                   target='valid_dataset;args;wav_scp'),
        CustomArgs(['--u2l', '--utt2label_val'],
                   type=str,
                   target='valid_dataset;args;utt2label')
    ]
    config = ConfigParser.from_args(args, options)
    main(config)
    prediction_writer = PredictionKNPWriter(dataset, logger)
    with io.StringIO() as string:
        _ = prediction_writer.write(arguments_set, string, skip_untagged=False)
        knp_result = string.getvalue()
    with log_dir.joinpath('pas.knp').open('wt') as f:
        f.write(knp_result)
    return knp_result


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-r', '--resume', '-m', '--model', default=None, type=str,
                        help='path to trained checkpoint')
    parser.add_argument('--ens', '--ensemble', default=None, type=str,
                        help='path to directory where checkpoints to ensemble exist')
    parser.add_argument('-d', '--device', default='', type=str,
                        help='indices of GPUs to enable (default: all)')
    parser.add_argument('-c', '--config', default=None, type=str,
                        help='config file path (default: None)')
    parser.add_argument('--host', default='0.0.0.0', type=str,
                        help='host ip address (default: 0.0.0.0)')
    parser.add_argument('--port', default=12345, type=int,
                        help='host port number (default: 12345)')
    args = parser.parse_args()
    config = ConfigParser.from_args(args, run_id='')
    analyzer = Analyzer(config, logger=logger)

    server = SimpleXMLRPCServer((args.host, args.port))
    server.register_function(analyze_raw_data_from_client)
    server.serve_forever()
Esempio n. 6
0
        type=float,
        help=
        'threshold for argument existence. The higher you set, the higher precision gets. [0, 1]'
    )
    parser.add_argument(
        '--recall-threshold',
        default=0.0,
        type=float,
        help=
        'threshold for argument non-existence. The higher you set, the higher recall gets [0, 1]'
    )
    parser.add_argument('--result-suffix',
                        default='',
                        type=str,
                        help='custom evaluation result directory name')
    parser.add_argument('--run-id',
                        default=None,
                        type=str,
                        help='custom experiment directory name')
    parser.add_argument('--oracle',
                        action='store_true',
                        default=False,
                        help='use oracle dependency labels')
    parsed_args = parser.parse_args()
    inherit_save_dir = (parsed_args.resume is not None
                        and parsed_args.run_id is None)
    main(
        ConfigParser.from_args(parsed_args,
                               run_id=parsed_args.run_id,
                               inherit_save_dir=inherit_save_dir), parsed_args)

if __name__ == '__main__':
    print("n_gpu", str(torch.cuda.device_count()))
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--config',
                        default=None,
                        type=str,
                        help='config file path (default: None)')
    parser.add_argument('-r',
                        '--resume',
                        default=None,
                        type=str,
                        help='path to latest checkpoint (default: None)')
    parser.add_argument('-d',
                        '--device',
                        default='',
                        type=str,
                        help='indices of GPUs to enable (default: "")')
    parser.add_argument('--seed',
                        type=int,
                        default=42,
                        help='random seed for initialization')
    parser.add_argument("-f",
                        '--freeze_encoder',
                        action='store_true',
                        help='Freeze encoder during training')
    parsed_args = parser.parse_args()
    main(ConfigParser.from_args(parsed_args), parsed_args)