Beispiel #1
0
        # get the pretrained model prefix
        if params.load_model is None:
            pretrained_prefix = ''
        else:
            pretrained_prefix = os.path.basename(params.load_model)
            pretrained_prefix = '_' + pretrained_prefix[:pretrained_prefix.
                                                        find('.pth')]
        mlp_str = params.cldc_mlp_type if params.cldc_mlp_type == 'sl' else (
            params.cldc_mlp_type + params.activation +
            str(params.cldc_do_rate))
        cldc_str = (
            '{}red.{}_'.format(params.task_type, params.cldc_train_mode) +
            ('{}_'.format(params.semicldc_yprior_type)
             if params.task_type == 'semi-cldc' else '') +
            ('{}_'.format(params.semicldc_cond_type)
             if params.task_type == 'semi-cldc' else '') +
            'train.{}_'.format(params.cldc_train_scale) +
            'val.{}_'.format(params.CLDC_VAL_EVERY) +
            '{}_'.format('2'.join(params.cldc_part)) + '{}_'.format(mlp_str) +
            'lr.{}_'.format(params.cldc_init_learning_rate) +
            'per.{}_'.format(params.cldc_percentile) + 'pre.{}'.format(
                'n' if params.pretrained is None else params.pretrained))
        out_str = cldc_str + pretrained_prefix + '_' + cur_time
    return out_str


if __name__ == '__main__':
    arguments = create_args()
    params = Params(arguments)
    main(params)
Beispiel #2
0
    self.wdidx2moidx = torch.LongTensor(self.wdidx2moidx)
    self.momask = torch.Tensor(self.momask)
    if compf.startswith('pp') or compf.startswith('mp'):
      self.wdidx2pos = torch.LongTensor(self.wdidx2pos)


if __name__ == '__main__':
  import sys
  import os
  sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

  import torch 
  from args import create_args
  from sms.sms_input_data import SmsInputData
  from morf.morf_input_data import MorfInputData
  from bpe.bpe_input_data import BPEInputData
  from charn.charn_input_data import CharnInputData

  args = create_args()
  if args.subword == 'sms':
    data = SmsInputData(args)
  elif args.subword == 'morf':
    data = MorfInputData(args)
  elif args.subword == 'bpe':
    data = BPEInputData(args)
  elif args.subword == 'charn':
    data = CharnInputData(args)
  state_dict = {'mo2idx': data.mo2idx,
                'word2idx': data.word2idx}
  torch.save(state_dict, args.save_model)
Beispiel #3
0
                # Progress bar
                if opt.local_rank == 0:
                    pb.set_postfix(loss=loss,
                                   disto=disto,
                                   rate_y_0=rate_y_0,
                                   rate_z=rate_z,
                                   refresh=False)
                    pb.update()
    except KeyboardInterrupt:
        status_code = 130

    if opt.local_rank == 0:
        pb.close()
    print('Done')
    # Save model
    print('Saving...')
    torch.save(model.state_dict(), os.path.join(opt.save_path, 'model.pt'))
    return status_code


if __name__ == '__main__':
    # Arguments
    p = args.create_args()
    # Parse arguments
    opt = helper.DotDict(vars(p.parse_args()))
    # Disable output for all processes but the first one
    if opt.local_rank != 0:
        sys.stdout = open(os.devnull, "w")
    # Main
    main(opt)