def __init__(self, packer, l_map, SCRF_l_map): self.packer = packer self.l_map = l_map self.SCRF_l_map = SCRF_l_map self.r_l_map = utils.revlut(l_map) self.SCRF_r_l_map = utils.revlut(SCRF_l_map)
def __init__(self, packer, l_map, SCRF_l_map): self.packer = packer self.l_map = l_map self.SCRF_l_map = SCRF_l_map self.r_l_map = utils.revlut(l_map) self.SCRF_r_l_map = utils.revlut(SCRF_l_map) self.true_labels = [] self.scrf_pred_labels = [] self.crf_pred_labels = [] self.joint_pred_labels = []
ts, f2i, _ = conll_load_sentences(args.train, word_vocab, char_vocab, maxs, maxw, f2i, long_0_tensor_alloc) print('Loaded training data') if args.valid is not None: print('Using provided validation data') vs, f2i, _ = conll_load_sentences(args.valid, word_vocab, char_vocab, maxs, maxw, f2i, long_0_tensor_alloc) else: ts, vs = valid_split(ts, args.valsplit) print('Created validation split') es, f2i, txts = conll_load_sentences(args.test, word_vocab, char_vocab, maxs, maxw, f2i, long_0_tensor_alloc) print('Loaded test data') i2f = revlut(f2i) print(i2f) print('Using %d examples for training' % len(ts)) print('Using %d examples for validation' % len(vs)) print('Using %d examples for test' % len(es)) model = TaggerModel(f2i, word_vec, char_vec, maxs, maxw, args.rnn, args.wsz, args.hsz, args.cfiltsz, args.dropout, args.numrnn) trainer = Trainer(gpu, model, args.optim, args.eta, args.mom) outname = '%s/%s.model' % (args.outdir, args.save) max_acc = 0 last_improved = 0 for i in range(args.epochs): print('Training epoch %d' % (i + 1)) trainer.train(ts, args.batchsz)
embed1 = Word2VecModel(args.embed1, vocab1, args.unif) print('Loaded word embeddings: ' + args.embed1) if args.embed2 is None: print('No embed2 found, using embed1 for both') args.embed2 = args.embed1 embed2 = Word2VecModel(args.embed2, vocab2, args.unif) print('Loaded word embeddings: ' + args.embed2) ts = load_sentences(args.train, embed1.vocab, embed2.vocab, args.mxlen, args.batchsz, long_0_tensor_alloc) es = load_sentences(args.test, embed1.vocab, embed2.vocab, args.mxlen, args.batchsz, long_0_tensor_alloc) rlut1 = revlut(embed1.vocab) rlut2 = revlut(embed2.vocab) Seq2SeqModelType = Seq2SeqAttnModel if args.attn else Seq2SeqModel print(Seq2SeqModelType) seq2seq = Seq2SeqModelType(embed1, embed2, args.mxlen, args.hsz, args.layers, args.rnntype) trainer = Trainer(gpu, seq2seq, args.optim, args.eta, args.mom) err_min = 1 last_improved = 0 reset = 0 for i in range(args.epochs): print('Training epoch %d' % (i + 1))
def __init__(self, packer, l_map): self.packer = packer self.l_map = l_map self.r_l_map = utils.revlut(l_map)
f2i, args.clean, args.chars, args.mxlen, mxfiltsz, vec_alloc=long_0_tensor_alloc, ExType=TorchExamples) print('Loaded test data') nc = len(f2i) mdsave(f2i, embeddings.vocab, args.outdir, args.save) model = ConvModel(embeddings, nc, args.filtsz, args.cmotsz, args.hsz, args.dropout, not args.static) labels = revlut(f2i) trainer = Trainer(gpu, model, args.optim, args.eta, args.mom) max_acc = 0 last_improved = 0 confusion = ConfusionMatrix(labels) for i in range(args.epochs): print('Training epoch %d' % (i + 1)) trainer.train(ts, confusion, args.batchsz) this_acc = trainer.test(vs, confusion, args.batchsz, 'Validation') if this_acc > max_acc: max_acc = this_acc last_improved = i model.save(args.outdir, args.save) print('Highest dev acc achieved yet -- writing model')