def main(): embedding = np.load("data/wordvec_200.npy") vocab_size = embedding.shape[0] model = MwAN(embedding, vocab_size=vocab_size, embedding_size=args.emsize, encoder_size=args.nhid, drop_out=args.dropout) logger.info(model) logger.info("path to save the model {}".format(args.save)) print('Model total parameters:', get_model_parameters(model)) if args.cuda: model.cuda() if args.mode == 'train': optimizer = torch.optim.Adamax(model.parameters()) else:#'continue' optimizer = torch.optim.Adam(model.parameters(), lr=1e-4, betas=(0.9, 0.999), eps=1e-8, weight_decay=0) with open(args.data + 'train.pickle', 'rb') as f: train_data = pickle.load(f) with open(args.data + 'dev.pickle', 'rb') as f: dev_data = pickle.load(f) dev_data = sorted(dev_data, key=lambda x: len(x[1])) logger.info('train data size {:d}, dev data size {:d}'.format(len(train_data), len(dev_data))) best = 0.0 for epoch in range(args.epoch): acc = train(epoch, best, model, optimizer, train_data, dev_data) if acc > best: best = acc acc = test(model, dev_data) if acc > best: best = acc with open(args.save, 'wb') as f: torch.save(model, f) f.close() logger.info('epcoh {:d} validation acc is {:f}, best validation acc {:f}'.format(epoch, acc, best))
type=str, default='model.pt', help='path to save the final model') parser.add_argument('--word_path', type=str, default='data/word2id.obj', help='location of the word2id.obj') args = parser.parse_args() # vocab_size = process_data(args.data, args.threshold) vocab_size = 98745 model = MwAN(vocab_size=vocab_size, embedding_size=args.emsize, encoder_size=args.nhid, drop_out=args.dropout) print('Model total parameters:', get_model_parameters(model)) print(model) if args.cuda: model.cuda() optimizer = torch.optim.Adamax(model.parameters()) with open(args.data + 'train.pickle', 'rb') as f: train_data = cPickle.load(f) with open(args.data + 'dev.pickle', 'rb') as f: dev_data = cPickle.load(f) dev_data = sorted(dev_data, key=lambda x: len(x[1])) print('train data size {:d}, dev data size {:d}'.format( len(train_data), len(dev_data)))
help='# of batches to see the training error') parser.add_argument('--dropout', type=float, default=0.1, help='dropout applied to layers (0 = no dropout)') parser.add_argument('--cuda', action='store_true', help='use CUDA') parser.add_argument('--save', type=str, default='model_1.pt', help='path to save the final model') args = parser.parse_args() # vocab_size = process_data(args.data, args.threshold) embedding = np.load("/home/zhengyinhe/xie_data/data/tencent_wordvec_200.npy") vocab_size = embedding.shape[0] print(vocab_size) model = MwAN(embedding, vocab_size, heads=8, embedding_size=args.emsize, encoder_size=args.nhid, conv_num=4, attn_num=1, drop_out=args.dropout) logger.info(model) logger.info("path to save the model {}".format(args.save)) print('Model total parameters:', get_model_parameters(model)) if args.cuda: model.cuda() optimizer = torch.optim.Adamax(model.parameters()) with open(args.data + 'train.pickle', 'rb') as f: train_data = pickle.load(f) with open(args.data + 'dev.pickle', 'rb') as f: dev_data = pickle.load(f) dev_data = sorted(dev_data, key=lambda x: len(x[1])) logger.info('train data size {:d}, dev data size {:d}'.format(len(train_data), len(dev_data)))
help='of batches to see the validation result') parser.add_argument('--dropout', type=float, default=0.0, help='dropout applied to layers (0 = no dropout)') parser.add_argument('--cuda', action='store_true', help='use CUDA') parser.add_argument('--save', type=str, default='model_3.pt', help='path to save the final model') args = parser.parse_args() # vocab_size = process_data(args.data, args.threshold) embedding = np.load("/home/zhengyinhe/xie_data/data2/tencent_wordvec_200.npy") vocab_size = embedding.shape[0] print(vocab_size) model = MwAN(embedding, vocab_size=vocab_size, embedding_size=args.emsize, encoder_size=args.nhid, drop_out=args.dropout) logger.info(model) logger.info("path to save the model {}".format(args.save)) print('Model total parameters:', get_model_parameters(model)) if args.cuda: model.cuda() embedding_params = list(map(id, model.embedding.parameters())) base_params = filter(lambda p: id(p) not in embedding_params, model.parameters()) with open(args.data + 'train.pickle', 'rb') as f: train_data = pickle.load(f) with open(args.data + 'dev.pickle', 'rb') as f: dev_data = pickle.load(f) dev_data = sorted(dev_data, key=lambda x: len(x[1]))