Ejemplo n.º 1
0
if __name__ == "__main__":
    Log.AppLogger.configure(mkdir=True)

    App.add_command(
        'decode', decode, {
            'gpu':
            arg('--gpu',
                '-g',
                type=int,
                default=-1,
                help='GPU ID (negative value indicates CPU)'),
            'model_file':
            arg('--modelfile',
                type=str,
                required=True,
                help='Trained model archive file'),
            'save_to':
            arg('--out',
                type=str,
                default=None,
                help='Save results to the specified directory'),
            'target_file':
            arg('--targetfile',
                type=str,
                required=True,
                help='Decoding target data file'),
        })

    App.run()
Ejemplo n.º 2
0
if __name__ == "__main__":
    App.configure(name='chainer-mnist', logoption='d')
    App.add_command(
        'train',
        train, {
            'batch_size':
            arg('--batchsize',
                '-b',
                type=int,
                default=100,
                help='Number of images in each mini-batch'),
            'device':
            arg('--device',
                type=int,
                default=-1,
                metavar='ID',
                help='Device ID (negative value indicates CPU)'),
            'n_epoch':
            arg('--epoch',
                '-e',
                type=int,
                default=20,
                help='Number of sweeps over the dataset to train'),
            'n_units':
            arg('--unit', '-u', type=int, default=1000,
                help='Number of units'),
        },
        description="Execute training")
    App.run()
Ejemplo n.º 3
0
 App.add_command(
     'train', train, {
         'batch_size':
         arg('--batchsize',
             type=int,
             default=20,
             metavar='NUM',
             help='Number of examples in each mini-batch'),
         'cache_dir':
         arg('--cachedir',
             type=str,
             default=(App.basedir + '/../cache'),
             metavar='DIR',
             help='Cache directory'),
         'test_file':
         arg('--devfile',
             type=str,
             default=None,
             metavar='FILE',
             help='Development data file'),
         'device':
         arg('--device',
             type=int,
             default=-1,
             metavar='ID',
             help='Device ID (negative value indicates CPU)'),
         'embed_file':
         arg('--embedfile',
             type=str,
             default=None,
             metavar='FILE',
             help='Pretrained word embedding file'),
         'n_epoch':
         arg('--epoch',
             type=int,
             default=20,
             metavar='NUM',
             help='Number of sweeps over the dataset to train'),
         'format':
         arg('--format',
             type=str,
             choices=('tree', 'genia'),
             default='tree',
             help='Training/Development data format'),
         'grad_clip':
         arg('--gradclip',
             type=float,
             default=5.0,
             metavar='VALUE',
             help='L2 norm threshold of gradient norm'),
         'encoder_input':
         arg('--inputs',
             type=str,
             choices=('char', 'postag', 'elmo', 'bert-base', 'bert-large'),
             nargs='*',
             default=('char', 'postag'),
             help='Additional inputs for the encoder'),
         'l2_lambda':
         arg('--l2',
             type=float,
             default=0.0,
             metavar='VALUE',
             help='Strength of L2 regularization'),
         'limit':
         arg('--limit',
             type=int,
             default=-1,
             metavar='NUM',
             help='Limit of the number of training samples'),
         'lr':
         arg('--lr',
             type=float,
             default=0.001,
             metavar='VALUE',
             help='Learning Rate'),
         'bert_model':
         arg('--bert_model',
             type=int,
             default=0,
             metavar='VALUE',
             help='Whether to use BERT model or not'),
         'bert_dir':
         arg('--bert_dir',
             type=str,
             default='',
             metavar='VALUE',
             help='Directory containing bert files'),
         'model_config':
         arg('--model',
             action='store_dict',
             metavar='KEY=VALUE',
             help='Model configuration'),
         'refresh_cache':
         arg('--refresh', '-r', action='store_true', help='Refresh cache'),
         'save_dir':
         arg('--savedir',
             type=str,
             default=None,
             metavar='DIR',
             help='Directory to save the model'),
         'seed':
         arg('--seed',
             type=int,
             default=None,
             metavar='VALUE',
             help='Random seed'),
         'train_file':
         arg('--trainfile',
             type=str,
             required=True,
             metavar='FILE',
             help='Training data file'),
     })
Ejemplo n.º 4
0
 App.add_command(
     'train', train, {
         'backend':
         arg('--backend',
             type=str,
             choices=('chainer', 'pytorch'),
             default='chainer',
             help='Backend framework for computation'),
         'batch_size':
         arg('--batchsize',
             '-b',
             type=int,
             default=32,
             help='Number of examples in each mini-batch'),
         'embed_file':
         arg('--embedfile',
             type=str,
             default=None,
             help='Pretrained word embedding file'),
         'embed_size':
         arg('--embedsize',
             type=int,
             default=100,
             help='Size of embeddings'),
         'gpu':
         arg('--gpu',
             '-g',
             type=int,
             default=-1,
             help='GPU ID (negative value indicates CPU)'),
         'lr':
         arg('--lr', type=float, default=0.002, help='Learning Rate'),
         'model_params':
         arg('--model',
             action='store_dict',
             default={},
             help='Model hyperparameter'),
         'n_epoch':
         arg('--epoch',
             '-e',
             type=int,
             default=20,
             help='Number of sweeps over the dataset to train'),
         'seed':
         arg('--seed', type=int, default=None, help='Random seed'),
         'save_to':
         arg('--out',
             type=str,
             default=None,
             help='Save model to the specified directory'),
         'test_file':
         arg('--validfile',
             type=str,
             default=None,
             help='validation data file'),
         'train_file':
         arg('--trainfile',
             type=str,
             required=True,
             help='training data file'),
     })
Ejemplo n.º 5
0
    trainer = training.Trainer(optimizer,
                               model,
                               loss_func=compute_loss,
                               accuracy_func=compute_accuracy)
    trainer.configure(framework_utils.config)

    trainer.fit(train_dataset,
                None,
                batch_size=batch_size,
                epochs=n_epoch,
                validation_data=test_dataset,
                verbose=App.verbose)


if __name__ == "__main__":
    logging.AppLogger.configure(mkdir=True)
    App.add_command(
        'train', train, {
            'train_file': arg('--trainfile', type=str, required=True),
            'test_file': arg('--testfile', type=str),
            'word_embed_file': arg('--embedfile', type=str),
            'n_epoch': arg('--epoch', type=int, default=20),
            'batch_size': arg('--batchsize', type=int, default=10),
            'lr': arg('--lr', type=float, default=0.01),
            'gpu': arg('--gpu', type=int, default=-1),
            'seed': arg('--seed', type=int, default=1),
        })
    chainer.config.debug = False
    chainer.config.type_check = False
    App.run()
Ejemplo n.º 6
0
 App.add_command(
     'train', train, {
         'batch_size':
         arg('--batchsize',
             type=int,
             default=5000,
             metavar='NUM',
             help='Number of tokens in each mini-batch'),
         'cache_dir':
         arg('--cachedir',
             type=str,
             default=(App.basedir + '/../cache'),
             metavar='DIR',
             help='Cache directory'),
         'test_file':
         arg('--devfile',
             type=str,
             default=None,
             metavar='FILE',
             help='Development data file'),
         'device':
         arg('--device',
             type=int,
             default=-1,
             metavar='ID',
             help='Device ID (negative value indicates CPU)'),
         'embed_file':
         arg('--embedfile',
             type=str,
             default=None,
             metavar='FILE',
             help='Pretrained word embedding file'),
         'n_epoch':
         arg('--epoch',
             type=int,
             default=300,
             metavar='NUM',
             help='Number of sweeps over the dataset to train'),
         'lr':
         arg('--lr',
             type=float,
             default=2e-3,
             metavar='VALUE',
             help='Learning rate'),
         'model_config':
         arg('--model',
             action='store_dict',
             metavar='KEY=VALUE',
             help='Model configuration'),
         'refresh_cache':
         arg('--refresh', '-r', action='store_true', help='Refresh cache.'),
         'save_dir':
         arg('--savedir',
             type=str,
             default=None,
             metavar='DIR',
             help='Directory to save the model'),
         'seed':
         arg('--seed',
             type=int,
             default=None,
             metavar='VALUE',
             help='Random seed'),
         'train_file':
         arg('--trainfile',
             type=str,
             required=True,
             metavar='FILE',
             help='Training data file.'),
     })
Ejemplo n.º 7
0
 App.add_command('train', train, {
     'batch_size':
     arg('--batchsize', '-b', type=int, default=32,
         help='Number of examples in each mini-batch'),
     'embed_file':
     arg('--embedfile', type=str, default=None,
         help='Pretrained word embedding file'),
     'embed_size':
     arg('--embedsize', type=int, default=100,
         help='Size of embeddings'),
     'gpu':
     arg('--gpu', '-g', type=int, default=-1,
         help='GPU ID (negative value indicates CPU)'),
     'grad_clip':
     arg('--gradclip', type=float, default=5.0,
         help='L2 norm threshold of gradient norm'),
     'l2_lambda':
     arg('--l2', type=float, default=0.0,
         help='Strength of L2 regularization'),
     'lr':
     arg('--lr', type=float, default=0.001,
         help='Learning Rate'),
     'n_epoch':
     arg('--epoch', '-e', type=int, default=20,
         help='Number of sweeps over the dataset to train'),
     'seed':
     arg('--seed', type=int, default=1,
         help='Random seed'),
     'save_to':
     arg('--out', type=str, default=None,
         help='Save model to the specified directory'),
     'tasks':
     arg('--task', type=str, default='tp',
         help='Tasks to train: {t: tagging, p: parsing}'),
     'test_file':
     arg('--validfile', type=str, default=None,
         help='validation data file'),
     'train_file':
     arg('--trainfile', type=str, required=True,
         help='training data file'),
 })